Search code examples
clinuxsocketsepollberkeley-sockets

epoll ET, what events should I subscribe to on listening socket?


I have a fd:

socket(AF_INET6, SOCK_STREAM, ...)
bind(fd, ...)
listen(fd, ...)

And I have a epoll instance. I need to know, what events should I subscribe to via epoll_ctl? I need Edge Triggered mode.

I have those flags atm: EPOLLET | EPOLLIN

Should I subscribe to EPOLLRDHUP, EPOLLOUT, EPOLLPRI ?

Should I handle EPOLLHUP, EPOLLERR ? Why they can occur?


Solution

  • You ask specifically about the passive socket used to accept incoming connection requests. The example in man epoll doesn't subscribe to EPOLLRDHUP, EPOLLOUT, EPOLLPRI for the listening socket, and understandably so:

    • EPOLLOUT means: Writing now will not block. - There is no writing on the passive socket.
    • EPOLLRDHUP applies to connections. There isn't a connection on the passive socket.
    • EPOLLPRI means: There is urgent data to read. There's no urgent data on a passive socket.

    Also the example doesn't handle EPOLLHUP, EPOLLERR for the listening socket. That's at least understandable for EPOLLHUP, since that applies to output only. I know of no case where EPOLLERR would be returned for the passive socket.