I use TCP Keep-Alive option to detect dead connection. It works well with connection that use reading sockets:
setsockopt(mysock,...) // set various keep alive options
epoll_ctl(ep,mysock,{EPOLLIN|EPOLERR|EPOLLHUP},)
epoll_wait -> (exits after several seconds when remove host disconnects cable)
Epoll wait exits with EPOLLIN|EPOLLHUP on socket without a problem.
However if I try to write a lot to socket till I get EAGAIN and then poll for both reading and writing I don't get a error when I disconnect the cable:
setsockopt(mysock,...) // set various keep alive options
while(send() != EAGAIN)
;
epoll_ctl(ep,mysock,{EPOLLIN|EPOLLOUT|EPOLERR|EPOLLHUP},)
epoll_wait -> --- Never exits!!!! even when the cable of the remove host is disconnected!!!
- How can this be solved?
- Have anybody seen a similar problem?
- Any possible direction?
Edit: Additional Information
When I monitor the communication with wireshark, in the first case (of reading) I get once in several seconds request for ack. But in the second case I don't detect ones at all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…