在 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 调用中依赖什么语义?即使 events = 0,是否仍会传递任何事件?
最佳答案
它应该是有效的,并且 EPOLLERR
和 EPOLLHUP
始终包含在内,即使您没有请求它们,因此设置 events = 0
仍会对这两个事件做出回应。
不过请记住检查 epoll_ctl
的返回值。
文档指出:
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.
关于c++ - 将事件设置为零的文件描述符添加到 epoll 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54900175/