CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Need some clarification on overlapped ReadFile call

    I'm reading data from a named pipe using ReadFile(). The pipe was created with an overlapped flag, thus ReadFile also has overlapped structure supplied for it. From the documentation at MSDN it's clear that in this situation ReadFile() may return FALSE and later when the OVERLAPPED::hEvent event is set to signaled I can call GetOverlappedResult() to see how many bytes were actually read.

    But, what MSDN doesn't say is that sometimes ReadFile() returns TRUE (say, if the data being read is not long), so what shall I do in that case? Shall I still call GetOverlappedResult() to see how many bytes were read, or rely on the 'lpNumberOfBytesRead' parameter from ReadFile itself?

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Need some clarification on overlapped ReadFile call

    If the call returns true, the data is there and it's as if you made the call non overlapped. the buffer will be filled for the amount of data in the lpNumberOfBytesRead.

    This can happen if the data is already in the local buffers/cache and didn't have to actually be fetched remotely of via a slow medium.

    If it returns false, and GetlastError is ERROR_IO_PENDING, then the data isn't immediately available, no data has been copied into the buffer, and you'll get informed through the event when that data has actually arrived.

  3. #3
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Need some clarification on overlapped ReadFile call

    Thanks. So again, just to clarify because MSDN isn't quite clear on it:

    Calling GetOverlappedResult() when a previous overlapped operation returned TRUE is not correct, right?

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Need some clarification on overlapped ReadFile call

    I've no idea. Never tried to use it that way. It's possible that the overlappedresult would be valid also, the help for GetOverlappedResult() does seem to indicate it works that way.

  5. #5
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Need some clarification on overlapped ReadFile call

    Quote Originally Posted by OReubens View Post
    I've no idea. Never tried to use it that way. It's possible that the overlappedresult would be valid also, the help for GetOverlappedResult() does seem to indicate it works that way.
    That's my problem too, I have no idea either. It's just kind of counterintuitive to call it if the previous function returns FALSE. But nonetheless, it does seem to work both ways on XP, but my concern is that Vista and Win 7 may have a more strict rules.

    PS. It seems like not many people actually use those named pipes for the IPC, so additional documentation is hard to come by.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured