CancelIo() is supposed to cancel all pending I/O operations associated with the calling thread. In my experience, CancelIo() sometimes cancels future I/O operations as well. Given:
ReadFile(port, buffer, length, &bytesTransferred, overlapped);
- If I invoke
CancelIo(port)
immediately before the read,GetQueuedCompletionStatus()
will block forever, never receiving the read operation. - If I invoke
CancelIo(port)
immediately after the read,GetQueuedCompletionStatus()
will return 0 withGetLastError()==ERROR_OPERATION_ABORTED
- If I invoke
CancelIo(port)
and there are no pending or subsequent reads,GetQueuedCompletionStatus()
will block forever.
The key point here is that there is no way to detect when CancelIo()
has finished executing. How can I ensure that CancelIo()
is done executing and it is safe to issue further read requests?
PS: Looking at http://osdir.com/ml/lib.boost.asio.user/2008-02/msg00074.html and http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/using.html it sounds like CancelIo() is not really usable. Must customer requires Windows XP support. What are my options?
NOTE: I am reading from a serial port.