需要解释 `kevent` 过滤器的措辞
Need an explanation on wording of `kevent` filter
我在 man
中有以下 kevent
行:
EVFILT_TIMER Establishes an arbitrary timer identified by ident.
When adding a timer, data specifies the moment to
fire the timer (for NOTE_ABSTIME) or the timeout
period. The timer will be periodic unless EV_ONESHOT
or NOTE_ABSTIME is specified. On return, data
contains the number of times the timeout has expired
since the last call to kevent(). For non-monotonic
timers, this filter automatically sets the EV_CLEAR
flag internally.
The filter accepts the following flags in the fflags
argument:
NOTE_SECONDS data is in seconds.
NOTE_MSECONDS data is in milliseconds.
NOTE_USECONDS data is in microseconds.
NOTE_NSECONDS data is in nanoseconds.
NOTE_ABSTIME The specified expiration time is
absolute.
If fflags is not set, the default is milliseconds.
On return, fflags contains the events which triggered
the filter.
现在,我不明白最后一行:
On return, fflags contains the events which triggered the filter.
我的意思是字面意思,我看不懂这句话。根据定义,事件是一个结构。 fflags
如何包含“事件”?
更新
EVFILT_TIMER
的 fflags
的 return 值与传入的值相同。感谢接受答案的 OP。
根据 FreeBSD-13.0-RELEASE-p11
来源:
从我们在/usr/src/sys/kern/kern_event.c
中看到的(作为使用示例):
static int
filt_proc(struct knote *kn, long hint)
{
struct proc *p;
u_int event;
p = kn->kn_ptr.p_proc;
if (p == NULL) /* already activated, from attach filter */
return (0);
/* Mask off extra data. */
event = (u_int)hint & NOTE_PCTRLMASK;
/* If the user is interested in this event, record it. */
if (kn->kn_sfflags & event)
kn->kn_fflags |= event;
/* Process is gone, so flag the event as finished. */
if (event == NOTE_EXIT) {
kn->kn_flags |= EV_EOF | EV_ONESHOT;
kn->kn_ptr.p_proc = NULL;
if (kn->kn_fflags & NOTE_EXIT)
kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
if (kn->kn_fflags == 0)
kn->kn_flags |= EV_DROP;
return (1);
}
return (kn->kn_fflags != 0);
}
上面u_int event
的值来自/usr/include/sys/event.h
中的一些定义,也是u_int
。
因此,fflags
用作 input 和 output 以及在手册页中定义的:
The predefined system filters are listed below. Arguments may be passed to and from the filter via the fflags and data fields in the kevent structure.
您会在 /usr/include/sys/event.h
中找到 fflags
引用的 event
我在 man
中有以下 kevent
行:
EVFILT_TIMER Establishes an arbitrary timer identified by ident.
When adding a timer, data specifies the moment to
fire the timer (for NOTE_ABSTIME) or the timeout
period. The timer will be periodic unless EV_ONESHOT
or NOTE_ABSTIME is specified. On return, data
contains the number of times the timeout has expired
since the last call to kevent(). For non-monotonic
timers, this filter automatically sets the EV_CLEAR
flag internally.
The filter accepts the following flags in the fflags
argument:
NOTE_SECONDS data is in seconds.
NOTE_MSECONDS data is in milliseconds.
NOTE_USECONDS data is in microseconds.
NOTE_NSECONDS data is in nanoseconds.
NOTE_ABSTIME The specified expiration time is
absolute.
If fflags is not set, the default is milliseconds.
On return, fflags contains the events which triggered
the filter.
现在,我不明白最后一行:
On return, fflags contains the events which triggered the filter.
我的意思是字面意思,我看不懂这句话。根据定义,事件是一个结构。 fflags
如何包含“事件”?
更新
EVFILT_TIMER
的 fflags
的 return 值与传入的值相同。感谢接受答案的 OP。
根据 FreeBSD-13.0-RELEASE-p11
来源:
从我们在/usr/src/sys/kern/kern_event.c
中看到的(作为使用示例):
static int
filt_proc(struct knote *kn, long hint)
{
struct proc *p;
u_int event;
p = kn->kn_ptr.p_proc;
if (p == NULL) /* already activated, from attach filter */
return (0);
/* Mask off extra data. */
event = (u_int)hint & NOTE_PCTRLMASK;
/* If the user is interested in this event, record it. */
if (kn->kn_sfflags & event)
kn->kn_fflags |= event;
/* Process is gone, so flag the event as finished. */
if (event == NOTE_EXIT) {
kn->kn_flags |= EV_EOF | EV_ONESHOT;
kn->kn_ptr.p_proc = NULL;
if (kn->kn_fflags & NOTE_EXIT)
kn->kn_data = KW_EXITCODE(p->p_xexit, p->p_xsig);
if (kn->kn_fflags == 0)
kn->kn_flags |= EV_DROP;
return (1);
}
return (kn->kn_fflags != 0);
}
上面u_int event
的值来自/usr/include/sys/event.h
中的一些定义,也是u_int
。
因此,fflags
用作 input 和 output 以及在手册页中定义的:
The predefined system filters are listed below. Arguments may be passed to and from the filter via the fflags and data fields in the kevent structure.
您会在 /usr/include/sys/event.h
fflags
引用的 event