In the example:
event.events = EPOLLIN;
event.data.fd = fd;
int ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, event.data.fd, &event);
I pass the file descriptor in as both a member of event.data
and as an argument in its own right.
What does epoll_ctl
need the file descriptor twice?
This is a duplicate of about epoll_ctl()
The reason it needs it twice is that data
inside event
is a union
. epoll_ctl
does not know whether you actually provided a file descriptor or something else.
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;