Reputation: 135
I'll try keep this simple. I have the code below:
epoll_event event;
event.events = EPOLLIN | EPOLLET;
event.data.fd = clientSock; // this is equal to "7"
event.data.ptr = myPtr;
epoll_ctl(epoll, EPOLL_CTL_ADD, client, &event);
//Another thread
epoll_wait(epoll, &event2, MAX_EVENTS, EPOLL_TIMEOUT);
// This is the strange part...
cout << event2.data.fd; //output is different from "7"
But, if I dont add a ptr to event.data.ptr
(which I did before I called epoll_wait
), the value of event2.data.fd
is correct (7). What's causing this?
Upvotes: 0
Views: 346
Reputation: 181744
The type of the data
member of struct epoll_event
is a union
. As such, only one of its members contains a value at any given time, so when you assign to event.data.ptr
you replace the value previously written to event.data.fd
. The subsequent epoll_ctl
call therefore probably does not express interest in the events you think it does, but in any case, you should expect to read back only the ptr
member from the resulting event data, not the fd
member.
Upvotes: 1