我正在创建 Epoll 事件,在用户数据 epoll 结构中设置索引epoll_data
并将它们添加到 Epoll。但是,当收到来自 Epoll 的调用时,该用户数据索引未初始化。
代码:
class Epoll
{
Epoll()
{
_epollFd = epoll_create1(0);
assert(_epollFd >= 0);
}
void addEvent()
{
struct epoll_event event;
event.events = EPOLLIN;
event.data.u32 = getIndexFromSomwhere(); // This is set with/prints 0
int sock = getSockFromSomewhere();
assert(epoll_ctl(_epollFd, EPOLL_CTL_ADD, sock, &event));
}
void receiveEvents()
{
while(true)
{
struct epoll_event events[MAX_SOCKETS];
const size_t count = epoll_wait(_epollFd, &events[0], sizeof(events), -1);
for(size_t j = 0; j < count; ++j)
{
const uint32_t callbackIndex = events[j].data.u32;
// This returns 32735, not 0 as expected
}
}
}
int _epollFd;
};