Number of kevents registered in kqueue

Seán C. Farley sean-freebsd at farley.org
Fri Dec 16 14:43:45 PST 2005


On Fri, 16 Dec 2005, John-Mark Gurney wrote:

> Seán C. Farley wrote this message on Fri, Dec 16, 2005 at 16:09 -0600:
>> 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.
>
> Why do you need this?  What is the point of calling kevent if you
> don't have an event to wake it up?  Can you give us an example of
> where you need to know that there isn't any events in the queue?  (I
> can't think of one, since using kqueue w/o events is pointless.)  I
> can't see how tracking the count will let you know which events are
> still in the kqueue... (second to last sentence)

If you register a number of events to be handled by a single kevent-loop
and they are deleted (by kevent() or EV_ONESHOT), it would be nice for a
way to see if there are any more kevents registered in the kqueue when
deciding to exit the loop (or program) or performing some special
operation when all events are gone.

>> 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.
>
> I would think that it would need to be documented when you can't close
> a descriptor..  Neither pipe nor socketpair documents that close can
> be called on them...

Good point.  It was just a thought for us beginners to kevents.  The
other calls have a multitude of sources for documentation.

Seán
-- 
sean-freebsd at farley.org


More information about the freebsd-hackers mailing list