在例子中:
event.events = EPOLLIN;
event.data.fd = fd;
int ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, event.data.fd, &event);
我将文件描述符作为 event.data
的成员和本身的参数传递。
什么epoll_ctl
需要文件描述符两次?
最佳答案
这是 about epoll_ctl() 的副本
它需要它两次的原因是 event
中的 data
是一个 union
。 epoll_ctl
不知道您实际上是否提供了文件描述符或其他内容。
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
关于file-descriptor - 为什么 epoll_ctl 需要两次文件描述符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56974063/