Could you guys provide me a good sample code using EPOLLHUP for dead peer handling? I know that it is a signal to detect a user disconnection but not sure how I can use this in code..Thanks in advance..
相关问题
- Is shmid returned by shmget() unique across proces
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
You use
EPOLLRDHUP
to detect peer shutdown, notEPOLLHUP
(which signals an unexpected close of the socket, i.e. usually an internal error).Using it is really simple, just "or" the flag with any other flags that you are giving to
epoll_ctl
. So, for example instead ofEPOLLIN
writeEPOLLIN|EPOLLRDHUP
.After
epoll_wait
, do anif(my_event.events & EPOLLRDHUP)
followed by whatever you want to do if the other side closed the connection (you'll probably want to close the socket).Note that getting a "zero bytes read" result when reading from a socket also means that the other end has shut down the connection, so you should always check for that too, to avoid nasty surprises (the
FIN
might arrive after you have woken up fromEPOLLIN
but before you callread
, if you are in ET mode, you'll not get another notification).