Re: How do you get ECONNRESET on recv?
- From: Andrei Voropaev <avorop@xxxxxxx>
- Date: Thu, 9 Aug 2007 16:42:47 +0000 (UTC)
On 2007-08-09, chsalvia@xxxxxxxxx <chsalvia@xxxxxxxxx> wrote:
The man page for recv and read list the error ECONNRESET as an error
condition that happens when "A connection was forcibly closed by a
peer." I take this to mean that, assuming a TCP connection, if a
client is recv'ing from a server, and the server suddenly crashes,
then on the client side recv will return -1 and set errno to
ECONNRESET.
Well, your understanding is probably wrong.
The TCP answers with RESET when you try to send some data to peer that
does not want to read that data. In other words the peer has closed
connection or has done shutdown of reading.
Normally, if the peer closes connection, recv returns 0 without any
error. The same applies to the cases when the peer application crashes.
Now, if you try to send the data to peer after you got 0 from recv,
you should get RESET. If you try to send the data after you got RESET,
you'll get EPIPE or SIGPIPE.
So, theoretically, you can see ECONNRESET in recv only if the peer does
shutdown(SHUT_RD) and you try to send some data after this. Which
usually never happens :) More often the peer closes socket unexpectedly
while you are sending many chunks of data and as result you get
SIGPIPE, because your first send triggers RESET, and your second send
triggers SIGPIPE, because you didn't see the RESET.
--
Minds, like parachutes, function best when open
.
- Follow-Ups:
- Re: How do you get ECONNRESET on recv?
- From: James Carlson
- Re: How do you get ECONNRESET on recv?
- References:
- How do you get ECONNRESET on recv?
- From: chsalvia
- How do you get ECONNRESET on recv?
- Prev by Date: Re: fork on multiple cpu server
- Next by Date: grep to find content in between curly braces, "{" and "},"
- Previous by thread: How do you get ECONNRESET on recv?
- Next by thread: Re: How do you get ECONNRESET on recv?
- Index(es):
Relevant Pages
|
|