Question

I'm emulating a certain functionality of kqueue to handle events in my Centos box (I'm porting some code from FreeBSD), but I'm failing to understand the purpose of void *udata in struct kevent:

struct kevent {
         uintptr_t ident;        /* identifier for this event */
         short     filter;       /* filter for event */
         u_short   flags;        /* action flags for kqueue */
         u_int     fflags;       /* filter flag value */
         intptr_t  data;         /* filter data value */
         void      *udata;       /* opaque user data identifier */
     };

I've tried searching, but the longest form of literature I could find about this field is "Opaque user-defined value passed through the kernel unchanged." Which is not helping much.

Can anyone please explain to me clearly what this field is? And what someone could use it for?

Was it helpful?

Solution

The udata field is passed in and out of the kernel unchanged, and is not used in any way. The usage of this field is entirely application dependent, and is provided as a way to efficiently implement a function dispatch routine, or otherwise add an application identifier to the kevent structure.

for complete reference, please check out the following paper:

Kqueue: A generic and scalable event notification facility

OTHER TIPS

swpd is correct. I'd just like to add, that the concept of "user data" is widely used in event-handling APIs and the ones, where a callback function is provided by the caller. The user data (typically a void-pointer) is passed back verbatim.

Another example of user data is (web) cookies -- when a web-server sets Set-Cookie header, it asks the browser to sent the content back (in a Cookie-header) with each subsequent request. The browser is not expected to interpret the cookies in any way -- just as the kernel makes no interpretation of the udata-field -- just send it back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top