向事件设置为零的 epoll 添加文件描述符是否有效?
Is it valid to add a file descriptor to epoll with events set to zero?
将 epoll_event.events 设置为零的文件描述符添加到 epoll 是否有效?调用 epoll_wait 时预期会发生什么?请参阅简化示例:
struct epoll_event event = {};
event.data.fd = fd;
event.events = 0;
epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event);
epoll_wait(efd, &event, 1, -1);
在此实例中,我可以从 epoll_wait 调用中依赖什么语义?是否有任何事件即使在事件 = 0 时仍会传送?
它应该是有效的,而且 EPOLLERR
和 EPOLLHUP
总是包括在内,即使您没有请求它们,所以设置 events = 0
仍然会响应这两个事件。
不过记得检查 epoll_ctl
的 return 值。
文档指出:
The events member is a bit mask composed by ORing together zero or more of the following available event types:
EPOLLERR
Error condition happened on the associated file descriptor. This event is also reported for the write end of a pipe
when the read end has been closed. epoll_wait(2) will always report
for this event; it is not nec‐
essary to set it in events.
EPOLLHUP
Hang up happened on the associated file descriptor. epoll_wait(2) will always wait for this event; it is not necessary to set it in events.
将 epoll_event.events 设置为零的文件描述符添加到 epoll 是否有效?调用 epoll_wait 时预期会发生什么?请参阅简化示例:
struct epoll_event event = {};
event.data.fd = fd;
event.events = 0;
epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event);
epoll_wait(efd, &event, 1, -1);
在此实例中,我可以从 epoll_wait 调用中依赖什么语义?是否有任何事件即使在事件 = 0 时仍会传送?
它应该是有效的,而且 EPOLLERR
和 EPOLLHUP
总是包括在内,即使您没有请求它们,所以设置 events = 0
仍然会响应这两个事件。
不过记得检查 epoll_ctl
的 return 值。
文档指出:
The events member is a bit mask composed by ORing together zero or more of the following available event types:
EPOLLERR Error condition happened on the associated file descriptor. This event is also reported for the write end of a pipe when the read end has been closed. epoll_wait(2) will always report for this event; it is not nec‐ essary to set it in events.
EPOLLHUP Hang up happened on the associated file descriptor. epoll_wait(2) will always wait for this event; it is not necessary to set it in events.