Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

When reading from a channel such as a pipe or a stream socket, this event merely indicates that the peer closed its end of the channel.

EPOLLRDHUP

Stream socket peer closed connection, or shut down writing half of connection.

I can hardly tell any difference between EPOLLHUP and EPOLLRDHUP .

To me, whenever EPOLLRDHUP is used EPOLLHUP can be used instead with the same semantics.

Am I right? If not, any explanations?

EPOLLHUP means you can't write, EPOLLRDHUP (and read()==0) means you can't read. medium.com/where-the-flamingcow-roams/… n. m. Aug 14, 2018 at 3:51 No. EPOLLHUP means you half-close the socket and the peer half-closes the socket too. (So you can't either read or write) See stackoverflow.com/questions/52976152/… . kbridge4096 Jul 9, 2019 at 11:36 They mean slightly different things and require different handling. Read the man page for shutdown (2) hookenz Mar 11, 2021 at 3:03
  • EPOLLHUP means that the peer closed their end of the connection. Writing to the connection is closed , and after any (possible) readable data is consumed, reading from the connection is closed, too.
  • EDPOLLRDHUP only means that the peer closed their connection, or only half of their connection. If it's only halfway closed, the stream socket turns into a one-way, write-only connection. Writing to the connection may still be open , but after any (possible) readable data is consumed, reading from the connection is closed.
  • This may be done if the peer calls shutdown() on their socket descriptor, disallowing itself from writing data:

    #include <sys/socket.h>
    int sockfd = /* ... */;
    shutdown(sockfd, SHUT_WR);
                    Not possible. The localhost cannot detect any difference between the peer closing the socket and shutting it down for output.
    – user207421
                    Mar 11, 2021 at 5:12
                    @user207421 I don't understand. Where did I say that localhost can tell the difference? Shut down for output in the perspective of the peer, or localhost?
    – Samuel Hunter
                    Mar 11, 2021 at 5:20