POLLNVAL
POLLNVAL
is equivalent to EBADF
: it means the file descriptor does not actually refer to any open file, i.e. it was closed or never open to begin with. This can never happen except as a result of a programming error or intentional attempt to query whether a file descriptor is invalid. External conditions, such as a peer closing its end of a network socket or pipe, can never close your file descriptor to your end of the socket or pipe. If it could, this would lead to massive vulnerabilities in basically any program using sockets/pipes/etc.
也就是说当文件描述符没有打开,或者实际上并未引用任何打开的文件,会有这个事件.
除非由于编程错误或故意尝试查询文件描述符是否无效,否则这种情况永远不会发生。
POLLHUP
相反,是说你这个fd是有效的, 但是处于这样一个状态:
A device has been disconnected, or a pipe or FIFO has been closed by the last process that had it open for writing. Once set, the hangup state of a FIFO shall persist until some process opens the FIFO for writing or until all read-only file descriptors for the FIFO are closed.
This event and POLLOUT are mutually-exclusive; a stream can never be writable if a hangup has occurred. However, this event and POLLIN, POLLRDNORM, POLLRDBAND, or POLLPRI are not mutually-exclusive. This flag is only valid in the revents bitmask;
it shall be ignored in the events member.
最简单的一个情况就是 , 管道的写端被关闭时 , 我们在读端会收到POLLHUP事件.
这个POLLHUP状态持续到打开FIFO写端或者关闭读端.
EPOLLHUP
详细的可以看一下这篇文章.