0

I have this strange situation where the read(2) system call is always returning number of bytes read as 0. I know that this happens when the EOF is reached or the bytes to be read is specifed as 0. I am quite sure that none of the above are true in this scenario.

Here is the code snippet which may help in understanding the problem statement.

    po=ACE_OS::lseek(file_hand,-(offset+4),SEEK_CUR);
    cout<<"po:"<<po<<endl;
    cout<<"file_hand: "<<file_hand<<endl;
    // Read message number.
    if (!(nobr = ACE_OS::read(file_hand,(char*)buffer,1)))
    {
            cout << "errno " << errno << endl;
            cout<<"Failed to read the message number"<<endl;
            ERROR("%s", "Failed to read the message number");
            ACE_OS::close(file_hand);
            return 0;
    }

The fd was opened in the below way. file_hand = ACE_OS::open(getFullPathName().c_str(), O_RDONLY,ACE_DEFAULT_OPEN_PERMS);

samairtimer
  • 826
  • 2
  • 12
  • 28
  • I think your code doesn't fit your description: you should check `nobr` for `== 0` to find EOF, but `errno` is not needed there. YOu need to check `errno` only if `nobr < 0`. – glglgl Nov 14 '12 at 08:30
  • @glglgl i did try that too.. this is diffrent version from many tries that i did. But eeven when i do that i mean thay way you specified nobr=0 . – samairtimer Nov 14 '12 at 08:41

0 Answers0