EPOLLRDHUP not reliable

后端 未结 1 1459
无人及你
无人及你 2020-12-30 16:29

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\'

相关标签:
1条回答
  • 2020-12-30 17:25

    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.

    0 讨论(0)
提交回复
热议问题