views:

146

answers:

1

When asynchronous I/O (or "overlapped" I/O in Win32 jargon) is used, we need to deal with the OVERLAPPED structure and his hEvent member. If the I/O function will delay the read or write operation, we will get an ERROR_IO_PENDING error code, then we will wait the asynchronous operation to complete with a WaitForXxxEvent function, then we will call GetOverlappedResult.

However, if the I/O operation is immediately completed, we will not get ERROR_IO_PENDING, and in a read operation our read buffer will be filled immediately. But what about the OVERLAPPED::hEvent member? Will it be set to signaled state? I've not found a clear statement about that.

This question may seem pointless (why deal with the event if I know that the operation is already completed?), however I have a library that mimics the overlapped pattern and I need to have the same exact behavior.

+2  A: 

No it won't. It took me ages to figure that one out the hard way ;)

Goz
That's counter-intuitive... the documentation says that I/O functions that accept an OVERLAPPED will always reset the event (so we don't have to manually reset it before the call), and that the event will be signaled when the I/O operation will be completed. Now, if the I/O operation completes immediately, the event should be signaled when the I/O function return TRUE... hmm...
Lorenzo
I'm not going to say it confused the f**k out of me but I had MAJOR problems with the hEvent. In the end I just sacked it off and went with a "WaitForIOCompletion" function that would just sleep till it completed.
Goz