epoll_wait will return EPOLLHUP or EPOLLERR for the socket if the other side disconnects. EPOLLHUP and EPOLLERR are installed automatically, but you can also install a new EPOLLRDHUP, which explicitly reports peer disconnection.
Also, if you use send with the MSG_NOSIGNAL flag, it will set EPIPE to closed connections.
int resp = send (sock, buf, buflen, MSG_NOSIGNAL);
if (resp == -1 & & errno == EPIPE) {/ * the other side is gone * /}
Much better than getting a signal.
Martin Redmond Jun 22 '11 at 17:44 2011-06-22 17:44
source share