Significance of parameters in epoll_event structure (epoll)

epoll, linux, linux-kernel

Solution

The predefined union is for convinient usages and you will usually use only one of them:

- use ptr if you want to store a pointer

- use fd if you want to store socket descriptor

- use u32/u64 if you want to store a general/opaque 32/64 bit number

Actually epoll_data is 64bit data associated with a socket event for you to store anything to find event handler as epoll_wait returns just 2 things: the event & associated epoll_data.

Problem

I am using epoll_ctl() and epoll_wait() system calls. ``` int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event); int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); struct epoll_event { uint32_t events; /* epoll events (bit mask) */ epoll_data_t data; /* User data */ }; typedef union epoll_data { enter code here`void *ptr; /* Pointer to user-defined data */ int fd; /* File descriptor */ uint32_t u32; /* 32-bit integer */ uint64_t u64; /* 64-bit integer */ } epoll_data_t; ``` When using epoll_ctl, I can use the union epoll_data to specify the fd. One way is to specify it in "fd" member. Other way is to specify it in my own structure, "ptr" member will point to the structure. What is the use of "u32" and "u64" ? I went through the kernel system call implementation and found the following: 1. epoll_ctl initializes the epoll_event and stores it (in some RB tree format) 2. when fd is ready, epoll_wait returns epoll_event that was filled in epoll_ctl. After this I can identify the fd which becomes ready. I don't understand the purpose of "u32" and "u64".

Original source