0

Windows 8, x64.

Using overlapped Windows sockets Api with IOCP.

Noticed an unexpected behavior with sockets: For example, a call to DisconnectEx returns an error WSAENOTCONN but later I receive an event in GetQueuedCompletionStatusEx for exactly this disconnect (like it was still scheduled regardless of returned error). Same happens with AcceptEx (with different error returned, e.g. WSAEINVAL).

I was expecting the IOCP event to be scheduled only for pending operations (returned error code WSA_IO_PENDING), but not other errors.

EDIT: My question is: can IOCP events be scheduled by the system even if calls to DisconnectEx/AcceptEx return an error (WSAGetLastError) that is not WSA_IO_PENDING?

Thank you!

a_m
  • 369
  • 1
  • 3
  • 12

2 Answers2

1

IOCPs tend to flood you with statuses at seemingly odd times, including after you thought the handle was closed... The solution I used for this was to do a PostQueuedCompletionStatus() with a custom OVERLAPPED parameter to indicate "closed for real now" after I had closed the handle. Then any queued system statuses would be processed, and when I got the custom OVERLAPPED I knew I could free all my internal buffers related to the handle.

HerrJoebob
  • 2,264
  • 16
  • 25
  • Now that's a curious error. I've not encountered this one before. – Cory Nelson Dec 21 '12 at 22:52
  • May have been specific to my case, but like the OP I was using sockets in that project. In the absence of an actual question to answer I figured I'd share. :) – HerrJoebob Dec 21 '12 at 22:54
  • IOCPs provide one completion for each operation that is pending on the socket. Closing the socket doesn't prevent the completions, it may cause failure completions to occur (if, for example you have a read or write in progress at the time of closure). Nothing strange or unexpected about it if you understand the model. – Len Holgate Dec 22 '12 at 07:36
  • Unfortunately that does not answer my question. – a_m Dec 22 '12 at 14:27
  • Looks like it did... sounds like you didn't understand thd model... :) – Len Holgate Jan 03 '13 at 18:38
  • No unfortunately it didn't. That's why I decided to edit my original post with more concrete question. Thanks for response anyway. – a_m Feb 16 '13 at 19:31
0

The answer for the above question is no. The problem I had is I messed up scheduling several IOCP events on the same overlapped structure which resulted in this strange behavior.

a_m
  • 369
  • 1
  • 3
  • 12