views:

14

answers:

1

I have a list of a bunch of file descriptors that I have created kevents for, and I'm trying to figure out if there's any way to get the number of them that are ready for read or write access.

Is there any way to get a list of "ready" file descriptors, like what epoll_wait provides?

A: 

Events that occurred are placed into the eventlist buffer passed to the kevent call. So making this buffer sufficiently large will give you the list you are seeking. The return value of the kevent call will tell you have many events are in the eventlist buffer.

If using a large buffer is not feasible for some reason, you can always do a loop calling kevent with a zero timeout and a smaller buffer, until you get zero events in the eventlist.

Grrrr
Don't I need to pass a file descriptor in with the kevent call, though? I guess I'll need to play with this some more.
clee
You use the `kevent` call for both registering your interest in events of a certain kind, and for retrieving the events that actually occur. You can combine it in a single call, but you don't have to. Once you register you interest in a file descriptor, `kevent` will report relevant events for this descriptor, unless you used `EV_ONESHOT`, or deleted the event, or closed the descriptor.
Grrrr