1

When I call WSARecv() (or another Overlapped IO function), I could get an error immediately or I can get an error when I call GetQueuedCompletionStatus() to dequeue a completion packet.

So is it accurate to assume that I must handle the error returned (for example: WSAECONNABORTED) in these two places, or even if WSARecv() returned an error immediately, I will also receive the same error when calling GetQueuedCompletionStatus() and so I can only handle it in one place.

1 Answers1

1

A completion is only generated if you have a SUCCESS return or an error return where the resulting error is IO_PENDING. Any other error situation must be handled at the call site for the API in question, so at the WSARecv() call site. Once an overlapped operation has been started (SUCCESS or IO_PENDING returned from original API call) then this may also fail with an error which will be reported through the return value from GetQueuedCompletionStatus().

So, YES, you MUST handle errors in the correct places.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
  • +1 clear answer, by the way, very good elaboration on http://www.serverframework.com/asynchronousevents/2015/01/wsarecv-wsasend-and-thread-safety.html, do you plan second part more on WSAsend()? – maciekm Feb 27 '15 at 14:43
  • Once I've investigated the WSASend() side of that issue some more I may write some more. Right now I am just assuming that the same problem is possible and acting accordingly. – Len Holgate Feb 27 '15 at 15:33