1

One can use the GetOverlappedResult() function to get the number of read bytes from a successfull overlapped (asynchronous) ReadFile() operation.

I can't find a way to get the number of read bytes while the operation is still pending or after it has been aborted. The GetOverlappedResult() function seems to set the number of read bytes to 0 in both case. Any idea how to do that?

Edit: This asynchronous I/O operation is performed to retrieve data coming from an embedded device through a COM port. The operation is aborted after a timeout. I need the number of received bytes before operation was aborted only for debugging purpose.

greydet
  • 5,509
  • 3
  • 31
  • 51
  • You are asking for a time machine. This just isn't possible, you have to wait until the overlapped I/O request is complete. If you aborted it then of course you should not care. – Hans Passant Dec 20 '12 at 17:24
  • It would probably help if you described *why* you want to do this (i.e. what are you trying to solve that, knowing how much data is present-but-not-retrieved in an async-io request will solve for you). Chances are if it is for data stream integrity to restart the operation after "rewinding" to a prior state your model of async-transfer is probably broken from the get-go. – WhozCraig Dec 20 '12 at 18:19
  • @WhozCraig I edited my question to give more details on the context. So yes there are issues in the data stream integrity and I just want some information about what exactly was received. But maybe I should use the ClearComError function, which can fill a structure giving the number of bytes received and not yet read with a ReadFile. Is overlapped ReadFile leave data in this queue until there is enough data to complete the operation succesfully? – greydet Dec 20 '12 at 19:08

1 Answers1

1

The ClearComError function can fill a structure giving the number of bytes received and not yet consumed by a ReadFile operation.

greydet
  • 5,509
  • 3
  • 31
  • 51