POLLHUP vs POLLNVAL vs EPOLLHUP

POLLNVAL

POLLNVALis 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

詳細的可以看一下這篇文章.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章