c++ - 将事件设置为零的文件描述符添加到 epoll 是否有效?

标签 c++ c linux epoll

在 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,是否仍会传递任何事件?

最佳答案

它应该是有效的,并且 EPOLLERREPOLLHUP 始终包含在内,即使您没有请求它们,因此设置 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/

相关文章:

c++ - 计算字符数组中一行中的字符数

c - 填充 char* 数组时发生访问冲突

c - 循环遍历文件并在 C 中打印文件属性

C 查找所有出现的子字符串

c++ - 将两个 8 位数组组合成一个 USHORT (16 位),无循环

linux - 根据重复行值拆分文本文件的内容

c++ - 服务器监听本地主机:8080 can Apache still listen to port 80?

c++ - 使用MPI取数据临时使用然后返回结果

c++ - 显式复制构造函数

c++ - #include 在 C++ 枚举中的效果