1

我正在模拟 kqueue 的某些功能来处理我的 Centos 框中的事件(我正在从 FreeBSD 移植一些代码),但我无法理解void *udatain的目的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 */
     };

我试过搜索,但我能找到的关于这个字段的最长的文献形式是“不透明的用户定义的值通过内核保持不变”。这没有多大帮助。

谁能清楚地向我解释一下这个领域是什么?有人可以用它做什么?

4

2 回答 2

2

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

于 2013-03-25T05:25:28.933 回答
1

swpd 是正确的。我想补充一点,“用户数据”的概念广泛用于事件处理 API 和调用者提供回调函数的 API。用户数据(通常是空指针)逐字传回。

用户数据的另一个例子是(网络)cookies——当网络服务器设置 Set-Cookie 标头时,它会要求浏览器在每个后续请求中将内容发送回(在 Cookie 标头中)。浏览器不应该以任何方式解释 cookie——就像内核不解释 udata 字段一样——只需将其发送回来。

于 2013-04-10T22:23:56.373 回答