Answer the question
In order to leave comments, you need to log in
Why is the fd field in the epoll_event not set?
Hello!
After the epoll_wait method receives the EPOLLIN event, the epoll_event.data.fd structure field is set to 0, although the documentation says that there should be a client socket descriptor (by the way, the epoll_event.data.ptr field is filled in correctly).
int n = epoll_wait(epoll_fd, events, maxEvents, -1);
for (int i = 0; i < n; i++)
{
epoll_event e = events[i];
int s = e.data.fd; <---- всегда 0
}
int cfd = accept4(sfd, null, null, SOCK_NONBLOCK);
epoll_event e;
e.events = EPOLLIN;
e.data.fd = cfd;
e.data.ptr = (void*)cfd;
epoll_ctl(efd, EPOLL_CTL_ADD, cfd, &e);
epoll_event se;
se.data.fd = sfd;
se.events = EPOLLIN;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sfd, &se);
Answer the question
In order to leave comments, you need to log in
e.data.fd = cfd; e.data.ptr = (void*)cfd;
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
struct epoll_event {
uint32_t events; /* Epoll events */
epoll_data_t data; /* User data variable */
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question