Search code examples
linuxepoll

Semantically, why does epoll_wait sends me EPOLLIN, after read end had been shut down?


The question is straightforward. The shutdown(..., SHUT_RD) was called on the socket after read has returned zero. The epoll_wait keeps sending me EPOLLIN event for the socket. I know I can, and must do, in my situation, call epoll_ctl to modify the event mask. Naive thoughts lead me to think that, if close removes record from the epoll list, then shutdown had to mark appropriate socket end.

The question is, semantically, why epoll_wait do report me with read available, given that read returned 0 socket were shut down for reading?


Solution

  • epoll_wait() will report EPOLLIN if trying to read from the socket would return immediately rather than blocking.

    Once you do shutdown(..., SHUT_RD); all calls to read() return 0 immediately. Since it won't block, epoll_wait() reports that the socket is readable.