on epoll, the epoll_data structure is important
typedef union epoll_data {
void *ptr;
int fd;
__uint32_t u32;
__uint64_t u64;
} epoll_data_t;
if for some events, I need to relate it to some additional information, for the epoll_data, I need to construct a structure and use the ptr
to point to that structure. And inside the structure I put a fd
element, something like
typedef {
int fd;
char* info;
} compound;
but when I want to check the active event, I have to do something like:
for( ; ; )
{
nfds = epoll_wait(epfd,events,20,500);
for(i=0;i<nfds;++i)
{
if(events[i].data.fd==listenfd) {
...
}
else if( ((compound*)events[i].events.ptr)->fd ....){
...
}
}
the checking is inconsistent, sometimes I need to check events[i].data.fd
and sometimes I need to check events[i].data.ptr->fd
. If I put all events comsistent, namely, let all of them have a void ptr, for some sockets, it is a waste because they are not related to additional information.
so I think epoll_data should have a independent int fd
element because fd
is usually very important.
how is your opinion on this? thanks!