How to properly manage client disconnection?

Kevyn-Alexandre Paré kapare at
Tue May 22 21:32:35 CEST 2012


Here the source code of a simple server that accept one client.

When the client disconnect the callback for io is call infinitely with zero bytes recv.

Here the behaviour:

first terminal
1) ./main     
4) <-- READ: 0
5) <-- READ: 0
6) <-- READ: 0
7) <-- READ: 0

second terminal
2) nc localhost 19206

My questions are :

1) Can I assume that if the recv return zero mean that the client have been disconnected?
2) I register SIGPIPE I thought that I will receive a even of it when the clients disconnect but I don't?
3) What is the best way or recommended way to manage the clients disconnections and unregistered the socket from libev?

Best Regards,

-- Kevyn-Alexandre Pare
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.cxx
Type: application/octet-stream
Size: 4112 bytes
Desc: not available
URL: <>

More information about the libev mailing list