Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Dec 2005 00:25:14 +0200
From:      Vlad GALU <vladgalu@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: Number of kevents registered in kqueue
Message-ID:  <79722fad0512161425x31a8931dpda33cf71c29b7c54@mail.gmail.com>
In-Reply-To: <20051216155717.W4815@thor.farley.org>
References:  <20051216155717.W4815@thor.farley.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 12/17/05, Se=E1n C. Farley <sean-freebsd@farley.org> wrote:
> I may have missed it in the man page, but I am unable to find a way to
> determine how many kevents are currently registered within a kqueue.  If
> there is no method for a count, how about a way to find if a kqueue is
> empty or not.  Besides tracking what events are still within a kqueue,
> this would make for an easier way to write an event loop.  Currently,
> calling kevent() on an empty kqueue will still block.

   kevent() returns the number of events from the changelist, which is
at most nevents long. So you know already how many events you've
registered and how many of them were yielded. As for blocking on an
empty queue, you can get rid of it by passing a pointer to a zeroed
struct timespec as the last argument to kevent(). This usually works:

-- cut here --
 int ev =3D kevent(kq, NULL, 0, events, maxevents, &timeout); for (int i
=3D 0; i < ev; i++) ...
-- and here --

 where kq is the kqueue descriptor, events is a pointer to a struct
kevent array, maxevents is the maximum number of watched events and
timeout is a struct timespec with all members set to 0.
 For examples you can check thttpd/lighttpd and/org libevent, they all
provide wrappers around kqueue.



> Also, I recommend that the man page mention that a kqueue may be
> close(2)'d.  The only reference that it can be is that the manual page
> says the kqueue() call returns a descriptor.
>
> Se=E1n
> --
> sean-freebsd@farley.org
>
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org=
"
>
>


--
If it's there, and you can see it, it's real.
If it's not there, and you can see it, it's virtual.
If it's there, and you can't see it, it's transparent.
If it's not there, and you can't see it, you erased it.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?79722fad0512161425x31a8931dpda33cf71c29b7c54>