Does anyone know what a "well behaved" winsock app
is supposed to do when a call to recv() returns
SOCKET_ERROR and a subsequent call to
WSAGetLastError() returns WSAECONNRESET ?
Further more, what can one do to detect why
this error has occured ?
Thanks in advance.
Raman
>Hi!!
>
>Does anyone know what a "well behaved" winsock app
>is supposed to do when a call to recv() returns
>SOCKET_ERROR and a subsequent call to
>WSAGetLastError() returns WSAECONNRESET ?
The socket is now not connected, so clean it up.
>Further more, what can one do to detect why
>this error has occured ?
You sent data on a connected socket the system didn't know was
disconnected, but the other side said no to receiving it (the reset). You
might have had an error in a previous operation that was inadvertently
ignored, or maybe the peer silently dropped you.
Maybe your last call to recv() returned zero bytes. zero bytes is the
graceful close signal. Then you called recv() again and got that error
(?)
The winsock FAQ should have more info. I don't have a link handy. google
should find it for you easy.
>Thanks in advance.
>Raman
--
David Gravereaux <davy...@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]
> Does anyone know what a "well behaved" winsock app
> is supposed to do when a call to recv() returns
> SOCKET_ERROR and a subsequent call to
> WSAGetLastError() returns WSAECONNRESET ?
Close the socket.
> Further more, what can one do to detect why
> this error has occured ?
It occured because the computer on the other end asked you to reset the
connection. There are several reasons it might have done that and no easy
way to tell which of those things happened. The most likely causes are:
1) The application on the far end terminated abnormally, was closed by
the user without having a chance to close the connection, or closed the
connection in a disorderly way.
2) The computer on the far end rebooted and the new instance of the
operating system had no idea that the old instance had a connection to you.
3) The computer on the far end lost its connection to the Internet and a
different computer was assigned the same IP. Naturally, the new computer had
no idea the connection existed.
DS
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/win
sock/graceful_shutdown_linger_options_and_socket_closure_2.asp
On a WSAECONNRESET you should bypass the graceful shutdown process,
closesocket, and let all the sockets pending ops complete.
Here is the correct way to gracefully shutdown servers, and clients for
async tcp servers:
Server Style
On a zero byte recv completion you should:
1. Send any remaining data
2. Let all pending recvs drain
3. Call shutdown( SD_RECEIVE )
4. Let all pending sends drain
5. Call shutdown( SD_SEND )
6. Let any other pending operations drain
7. Call closesocket
Client Style
When your done sending data, and want to close you:
1. Let all pending sends drain
2. Call shutdown( SD_SEND )
3. Post recv's until zero byte completion
4. Let all pending recvs drain
5. Call shutdown( SD_RECEIVE )
6. Let any other pending operations drain
7. Call closesocket
--
The designer of the SMP and HyperThread friendly, AppCore library.