0

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]

Juarrow
  • 2,232
  • 5
  • 42
  • 61
  • Can you show us some code, please? – Aaron Klotz Mar 29 '11 at 15:49
  • which part do you need? if(GetQueuedCompletionStatus() == FALSE) or the GetLastError-Part? hahahaha ;)... Nah... to be honest... which part? ... There is no sense in posting it all from my point of view, because it´s a therory-thing as far as i see – Juarrow Mar 29 '11 at 15:55
  • You're making a big assumption there. Do you want help or not? – Aaron Klotz Mar 29 '11 at 16:08
  • yes... but my question still is: which part(s) do you need to fully understand it? it wouldnt make sense to post the creation of listenen socket etc... I just dont want to mess the OP up with posting too much irrelevant stuff – Juarrow Mar 29 '11 at 16:13
  • added the codepad-link to the parts of the code, i think that are responsible for this (at least the error occures there) – Juarrow Mar 29 '11 at 17:35
  • possible duplicate of [Calling WSAGetLastError() from an IOCP thread return incorrect result](http://stackoverflow.com/questions/28925003/calling-wsagetlasterror-from-an-iocp-thread-return-incorrect-result) – Hans Passant Mar 11 '15 at 10:20

2 Answers2

6

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.

Aaron Klotz
  • 11,287
  • 1
  • 28
  • 22
  • I encounter the last option. I guess I should read the socket out through the extended overlapped structure and close it. Thank you :) – Juarrow Mar 29 '11 at 20:48
  • I have a question plz. If `GetQueuedCompletionStatus` returns `FALSE`, `lpOverlapped != NULL`, is there one and only one packet has dequeued and this packet is faild? Only one? – LauZyHou Sep 05 '22 at 07:38
1

I know this is an old question, but I found this page while fruitlessly googling for details about ERROR_NETNAME_DELETED. It is an error which I get while doing an overlapped Readfile().

After some debugging it turned out that the problem was caused by a program which was writing to a socket but forgetting to call closesocket() before using ExitProcess() (due to garbage collection issues). Calling CloseHandle() did not prevent the error, nor did adding WSACleanup() before ExitProcess(). However, adding a short sleep before the client exited did prevent the error. Maybe avoiding ExitProcess() would have prevented the problem also.

So I suspect your problem is caused by the program exiting without closing down the socket properly.

I don't think this would be an issue on Unix where sockets are just ordinary file descriptors.

blah
  • 11
  • 1