I am writing a small server-client-stuff using an I/O-Completion Port.
I get the server and client connected successfully via AcceptEx over my completion port. After the client has connected the client socket is associated with the completion port and an overlapped call to WSARecv on that socket is invoked.
Everything works just fine, until I close the client test program.
GetQueuedCompletionStatus()
returns FALSE
and GetLastError
returns
ERROR_NETNAME_DELETED
, which makes sense to me (after I read the description on the MSDN).
But my problem is, that I thought the call to GetQueuedCompletionStatus
would return me a packet indicating the failure due to closure of the socket, because WSARecv
would return the apropriate return value.
Since this is not the case I don´t know which clients´ socket caused the error and cant act the way i need to (freeing structures , cleanup for this particular connection, etc)...
Any suggestion on how to solve this, Or hints?
Thanks:)
EDIT: http://codepad.org/WeYINasO <- the code responsible... the "error" occures at the first functions beginning of the while-loop (the call to GetCompletionStatus()
which is only a wrapper for GetQueuedCompletionStatus() working fine in other cases) [Did post it there, because it looks shitty & messy in here]
Here are the scenarios that you need to watch for when calling GetQueuedCompletionStatus
:
GetQueuedCompletionStatus
returns TRUE
: A successful completion packet has been received, all the out parameters have been populated.GetQueuedCompletionStatus
returns FALSE
, lpOverlapped == NULL
: No packet was dequeued. The other out parameters contain indeterminate values.GetQueuedCompletionStatus
returns FALSE
, lpOverlapped != NULL
: The function has dequeued a failed completion packet. The error code is available via GetLastError
.To answer your question, when GetQueuedCompletionStatus
returns FALSE
and lpOverlapped != NULL
, there was a failed I/O completion. It's the value of lpOverlapped
that you need to be concerned about.