IOCP: Post-Completion Error Codes for ConnectEx - Programmer

This is a discussion on IOCP: Post-Completion Error Codes for ConnectEx - Programmer ; 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) ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: IOCP: Post-Completion Error Codes for ConnectEx

  1. IOCP: Post-Completion Error Codes for ConnectEx

    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.



  2. Re: IOCP: Post-Completion Error Codes for ConnectEx

    On Feb 24, 5:42 pm, "Michael K. O'Neill"
    wrote:

    > 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?


    Call WSAGetOverlappedResult.
    http://msdn2.microsoft.com/en-us/library/aa921087.aspx

    DS

  3. Re: IOCP: Post-Completion Error Codes for ConnectEx

    > 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?


    If your call to GetQueuedCompletionStatus returns you can call
    GetLastError(). If the failure is IOCP related then the ppOverlapped
    that you passed in to GetQueuedCompletionStatus will remain null, if
    this isnt null but the function returned false then the error relates
    to the overlapped I/O operation that has completed. If that was a
    connectEx attempt the the error code that you get from GetLastError()
    is what you would have expected to get after the ConnectEx() call
    failed (had it been a synchronous call).

    Or call WSAGetOverlappedResult...

    Len


  4. Re: IOCP: Post-Completion Error Codes for ConnectEx


    "David Schwartz" wrote in message
    news:d95b65e6-209a-432e-8dd0-b170a1362d63@n77g2000hse.googlegroups.com...
    > On Feb 24, 5:42 pm, "Michael K. O'Neill"
    > wrote:
    >
    > > 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?
    >
    > Call WSAGetOverlappedResult.
    > http://msdn2.microsoft.com/en-us/library/aa921087.aspx
    >
    > DS


    Thank you both, David and Len, for pointing me to the
    WSAGetOverlappedResult() function.

    I suppose I should have realized this for myself. But in fairness, the
    documentation for WSAGetOverlappedResult() only mentions WSASend(To) and
    WSARecv(From); it doesn't mention ConnectEx() or other functions to which
    WSAGetOverlappedResult() probably also applies (like AcceptEx and
    DisconnectEx).




+ Reply to Thread