Michael K. O'Neill
2008-02-25 01:42:25 UTC
I'm using ConnectEx() as part of a stress-test client for an IOCP server, to
hammer the server with many simultaneous connections. I know that some of
the connection requests will fail, and I'm trying to determine (in the
client's code) when they do. But I can't figure out how to do so in the
completion thread.
The scenario is ordinary: call ConnectEx() with a NULL SendDataBuffer.
WSAGetLastError returns WSA_IO_PENDING. I get the completion notification
in a worker thread that's waiting on GetQueuedCompletionStatus(). Now, how
can I determine that the connection request has failed, or was successful?
With other socket architectures, this information is readily available.
With WSAAsyncSelect-based architectures, when you get an FD_CONNECT, the
connection error codes are in the HIWORD of the message's lParam. With
WSAEventSelect-based architectures, the call to WSAEnumNetworkEvents gives
you a WSANETWORKEVENTS structure, and you can use FD_CONNECT_BIT to index
into the error codes of the iErrorCode member.
If I were using these architectures, I would be looking for the
WSAECONNREFUSED error.
But I can't figure out how to do something similar for IOCP and ConnectEx().
If the connection request failed at the time of the call to ConnectEx(),
then of course I can see the WSAECONNREFUSED error. But I can't see how to
do that in the completion routine, after the call to ConnecEx() has
completed.
hammer the server with many simultaneous connections. I know that some of
the connection requests will fail, and I'm trying to determine (in the
client's code) when they do. But I can't figure out how to do so in the
completion thread.
The scenario is ordinary: call ConnectEx() with a NULL SendDataBuffer.
WSAGetLastError returns WSA_IO_PENDING. I get the completion notification
in a worker thread that's waiting on GetQueuedCompletionStatus(). Now, how
can I determine that the connection request has failed, or was successful?
With other socket architectures, this information is readily available.
With WSAAsyncSelect-based architectures, when you get an FD_CONNECT, the
connection error codes are in the HIWORD of the message's lParam. With
WSAEventSelect-based architectures, the call to WSAEnumNetworkEvents gives
you a WSANETWORKEVENTS structure, and you can use FD_CONNECT_BIT to index
into the error codes of the iErrorCode member.
If I were using these architectures, I would be looking for the
WSAECONNREFUSED error.
But I can't figure out how to do something similar for IOCP and ConnectEx().
If the connection request failed at the time of the call to ConnectEx(),
then of course I can see the WSAECONNREFUSED error. But I can't see how to
do that in the completion routine, after the call to ConnecEx() has
completed.