How to properly manage client disconnection?

Kevyn-Alexandre Paré kapare at
Wed May 23 18:07:50 CEST 2012

Hi Jonathan,

On 2012-05-22, at 3:47 PM, Jonathan Neuschäfer wrote:

> On Tue, May 22, 2012 at 03:32:35PM -0400, Kevyn-Alexandre Paré wrote:
>> 1) Can I assume that if the recv return zero mean that the client have been disconnected?
> Yes, that's what the manpage states:
> "The return value will be 0 when the peer has performed an orderly shutdown."

thx for confirming, my previous quick look at the help made me doubt because of the "orderly shutdown"….

Further reading help me to clarify my lack of comprehension ;)

Mac OS X 10.7 man recv is even more detail about that behaviour:

"For TCP sockets, the return value 0 means the peer has closed its half side of the connection."


Again, not read enough for the SIGPIPE:

EPIPE  "The socket is shut down for writing or the socket is connection-mode and is no longer connected.  In the latter case, and if the socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling thread."

An simple send after a read with zero bytes return a EPIPE and generate a SIGPIPE.


- KA

> Thanks,
> 	Jonathan Neuschäfer

More information about the libev mailing list