I\'m using non-blocking read/writes over a client-server TCP connection with epoll_wait
.
Problem is, I can\'t reliably detect \'peer closed connection\'
To answer this: EPOLLRDHUP
indeed comes if you continue to poll after receiving a zero-byte read.
So from my experiments it looks like either an EPOLLIN
with zero-byte read or an EPOLLRDHUP
are reliable indicators for orderly shutdown, the only trouble was, they are not received together. Sometimes (the case that makes the subject of this question), it happens that EPOLLIN is received, yielding zero bytes (connection terminated), and on subsequent polling you get to see the EPOLLRDHUP
. Other times, it's vice-versa: you get the EPOLLRDHUP
together with an EPOLLIN
that signals actual bytes to be read. Then, on subsequent reads, you get zero bytes.