RE: WSASend/WSARecv and IOCP GetQueuedCompletionStatus

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



1. When GetQueuedCompletionStatus(INFINITE) returns FALSE with not-null
overlapped. This means a WSASend/WSARecv has been failed. Do you think one of
the reason is that there is not enough non-paged pool buffer?


That is certainly a possibility if things go well. In the book "Network
Programming for Microsoft Windows 2nd Edition" (highly recommended) I'll
quote:

"If the system does run out of non-paged pool, there are two possibilities.
In the best-case scenario, Winsock calls will fail with WSAENOBUFS. The
worst-case scenario is the system crashes with a terminal error." (
http://www.microsoft.com/mspress/books/sampchap/5726a.aspx )

That book has a nice coverage of IOCP and TCP. I actually started my IOCP
work with TCP, but quickly switched to UDP due to resource constraints I hit
with TCP and needing UDP for game related programming.

So, recovery wise, I think it's better to program in such a way that error
shouldn't even happen. I.e., take a look at your server's resources and only
allow so many connections + locked buffers that should never surpass that
amount. How to go about that, well that's not so clear, but you should not
allow an unbounded amount of incoming connections (which is a DoS
vulnerability as well).

2. When GetQueuedCompletionStatus(INFINITE) return FALSE with null overlapped. This means IOCP has failed to extract I/O packet. I think this error does not relate to any specific socket.

I'd like to point you to some code I've found and studied when I got
started. It's got a few flaws, but it comes from a "trusted" site,
http://win32.mvps.org/network/sockhim.html

One of his comments in that code pertaining to that question says:

"if ( result == FALSE ) // something gone awry?
{
// something failed. Was it the call itself, or did we just eat
// a failed socket I/O?
if ( pov == 0 ) // the IOCP op failed
{
// no key, no byte count, no overlapped info available!
// how do I handle this?
// by ignoring it. I don't even have a socket handle to close.
// You might want to abort instead, as something is seriously
// wrong if we get here.
}
else
{
// key, byte count, and overlapped are valid.
// tear down the connection and requeue the socket
// (unless the listener socket is closed, in which case
// this is a failed AcceptEx(), and we stop accepting)
DoClose( *pov, true, listener == INVALID_SOCKET? false: true );
}
}
"

So, for when the overlapped is NULL, you are correct, something seriously is
broken and you should probably exit and have logged enough to determine what.
If just the IOCP extraction fails, then you close the socket and dispose of
it and create a new one as needed.

For some additional references that might help:
http://msdn.microsoft.com/en-us/library/cc500404.aspx
http://msdn.microsoft.com/en-us/library/aa365198(VS.85).aspx
http://msdn.microsoft.com/en-us/magazine/cc302334.aspx
http://www.amazon.com/exec/obidos/ASIN/0735615799/qid=1063940984/sr=2-1/ref=sr_2_1/002-4725947-6716828

I've consulted all of those so far in my progress using IOCP and UDP (which
I don't think there are any complete working examples, which is what I hope
to change ). I'll get back around to IOCP and TCP after my UDP work is done
though.

Best of luck!
.



Relevant Pages