If you received an event with EPOLLRDHUP=1 , just close the connection immediately without reading. If you get an event with EPOLLRDHUP=0 and EPOLLIN=1 , then go EPOLLIN=1 and read it, but you should be prepared for recv() to return 0 anyway, just in case. Maybe FIN will arrive after you get EPOLLIN=1 , but before you actually call recv() .
source share