Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Oct 2022 00:55:30 +0300
From:      =?UTF-8?B?0K/RgNC+0YHQu9Cw0LIg0JzQsNGI0LrQvg==?= <yaroslaw.mashko@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   clarification on kqueue kernel event flags.
Message-ID:  <CAMVwyx%2BpagV6%2Bcp%2BMJCOz=HYvxDCCEVQBVkVYpi-%2BY9X80XOPg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
--000000000000b76a3e05eb19cd12
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello,

I got confused with EV_CLEAR flag. Some code follows.

  kev.ident  =3D 1;
  kev.filter =3D EVFILT_TIMER;
  kev.flags  =3D EV_ADD | EV_DISPATCH;
  kev.data   =3D 4;
  kev.fflags =3D NOTE_SECONDS;

 l_reg_ev:
  status =3D kevent(kq, &kev, 1, NULL, 0, NULL);

  for(;;){
   status =3D kevent(kq, NULL, 0, &kev, 1, NULL);
   kev.flags =3D EV_ENABLE;
   goto l_reg_ev;
  }

This prints the series of:

id      :  1
> flags   :  EV_DISPATCH EV_CLEAR
> filter  :  EVFILT_TIMER
> data    :  # times timeout has expired since last kevent call: 1
>

The "man kevent", the EV_CLEAR section says that:

> After the event is retrieved by the user, its state is reset.
>

What I expect is that after the first goto, the EV_DISPATCH flag gets
cleared. What does "the state" mean in the above?
More specifically, what exactly EV_CLEAR changes with any combination of
flags and filters?

P.S.
I did read a source code for "/sys/kern/kern_event.c". My brain fails to
understand it as a whole, so, please be easy on me.

--=20
=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=D0=B2 =D0=9C=D0=B0=D1=88=D0=BA=D0=BE

+380 50 56 75 347 <+380+50+56+75+347>

--000000000000b76a3e05eb19cd12
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello,</div><div><br></div><div>I got confused with E=
V_CLEAR flag. Some code follows.</div><div><br></div><div>=C2=A0 kev.ident =
=C2=A0=3D 1;<br>=C2=A0 kev.filter =3D EVFILT_TIMER;<br>=C2=A0 kev.flags =C2=
=A0=3D EV_ADD | EV_DISPATCH;<br>=C2=A0 kev.data =C2=A0 =3D 4;<br>=C2=A0 kev=
.fflags =3D NOTE_SECONDS;</div><div><br></div><div>=C2=A0l_reg_ev:</div><di=
v>=C2=A0 status =3D kevent(kq, &amp;kev, 1, NULL, 0, NULL);</div><div><br><=
/div><div>=C2=A0 for(;;){</div><div>=C2=A0=C2=A0 status =3D kevent(kq, NULL=
, 0, &amp;kev, 1, NULL);</div><div>=C2=A0=C2=A0 kev.flags =3D EV_ENABLE;</d=
iv><div>=C2=A0=C2=A0 goto l_reg_ev;</div><div>=C2=A0 }</div><div><br></div>=
<div>This prints the series of:</div><div><br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex"><div>	id =C2=A0 =C2=A0 =C2=A0: =C2=A01<br>	flags=
 =C2=A0 : =C2=A0EV_DISPATCH EV_CLEAR <br>	filter =C2=A0: =C2=A0EVFILT_TIMER=
<br>	data =C2=A0 =C2=A0: =C2=A0# times timeout has expired since last keven=
t call: 1<br></div></blockquote><div>=C2=A0</div><div>The &quot;man kevent&=
quot;, the EV_CLEAR section says that: <br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204=
,204);padding-left:1ex"><div>After the event is retrieved by the user, its =
state is reset.</div></blockquote><div><br></div><div>What I expect is that=
 after the first goto, the EV_DISPATCH flag gets cleared. What does &quot;t=
he state&quot; mean in the above?</div><div>More specifically, what exactly=
 EV_CLEAR changes with any combination of flags and filters?</div><div><br>=
</div><div>P.S.<br></div><div>I did read a source code for &quot;/sys/kern/=
kern_event.c&quot;. My brain fails to understand it as a whole, so, please =
be easy on me.<br></div><div><br>-- <br><div dir=3D"ltr" class=3D"gmail_sig=
nature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=
=3D"ltr"><div><div dir=3D"ltr"><div><div dir=3D"ltr"><div dir=3D"ltr"><div =
dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"=
ltr"><div dir=3D"ltr"><div dir=3D"ltr">=D0=AF=D1=80=D0=BE=D1=81=D0=BB=D0=B0=
=D0=B2 =D0=9C=D0=B0=D1=88=D0=BA=D0=BE</div><div dir=3D"ltr"><br><div><a hre=
f=3D"tel:+380+50+56+75+347" target=3D"_blank">+380 50 56 75 347</a></div></=
div></div></div></div></div></div></div></div></div></div></div></div></div=
></div></div></div></div></div>

--000000000000b76a3e05eb19cd12--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMVwyx%2BpagV6%2Bcp%2BMJCOz=HYvxDCCEVQBVkVYpi-%2BY9X80XOPg>