In my project I need to read from and write to a serial port (RS232). I am using overlapped IO and use two separate threads for reading and writing.
When I issue a write operation that does not complete immediately, I start waiting (WaitForMultipleObjects) on two events; the event assigned to the hEvent member of the overlapped structure, and a stop event. When I want to stop the thread, I signal the stop event by calling SetEvent(). This causes the wait function to return. Because the write operation is still pending I cancel the operation by calling CancelIO(). Then again, I wait for the operation to complete, now using GetOverlappedResult() with the bWait parameter set to True. When the operation completes, GetOverlappedResult() returns False and GetLastError() returns ERROR_OPERATION_ABORTED.
Now here's my question:
When GetOverlappedResult() returns False, and GetLastError() returns ERROR_OPERATION_ABORTED (indicating a completed, but canceled operation), is the lpNumberOfBytesTransfered parameter valid? In other words, does the lpNumberOfBytesTransfered give me the actual number of written bytes before it was canceled? Or is the lpNumberOfBytesTransfered parameter undefined in this case?