-
June 9th, 2010, 03:49 PM
#1
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?
-
June 10th, 2010, 05:53 AM
#2
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.
-
June 10th, 2010, 11:55 AM
#3
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?
-
June 10th, 2010, 12:14 PM
#4
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.
-
June 10th, 2010, 12:45 PM
#5
Re: Need some clarification on overlapped ReadFile call
Originally Posted by OReubens
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|