Kqueue queries

2007-06-12 Thread Cole
Hi.

I just have a few queries regarding kqueue. Ive read through the tutorial
given on the netbsd page, as well as the pdf detailing kqueue.

What I want to do is write a single threaded server for listening for
connections, and then check if they are ready to be read from for each
connection.

Ive written the code for this already, and got it handling multiple
connections, the problem comes in when the sockets close. 

This is my kevent call:
nev = kevent(kq, events, number_events, changes, number_events, NULL);

I wanted to know, what must be done when the sockets/file descriptors close.
Do I need to decrease number_events and resort the events array so that all
the active kevents are sequential without any closed sockets still in that
array?

Or, is it possible, to just keep increasing kevents and leave the closed
socket/file descriptors in the events array, and just mark them as
EV_DISABLED | EV_DELETE?

When I detect a closed socket, I have tried the following, but to no evail:
close(changes[i].ident);
EV_SET(changes[i],changes[i].ident,EVFILT_READ,EV_DISABLE | EV_DELETE
,0,0,0);
kevent(kq, changes[i], 1, NULL, 0, NULL);

If I do the above, and just keep increasing number_events and just mark the
kevent as EV_DISABLED or EV_DELETE then all it does is return that event as
soon as I call kevent() with the following values:
ident : 7, filter : -1, flags : 16384

Any suggestions/help would be appreciated, as well as pointing out if im
doing something stupid here.

Regards
/Cole


___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Kqueue queries

2007-06-12 Thread James Bailie

Cole wrote:

 I wanted to know, what must be done when the sockets/file
 descriptors close.  Do I need to decrease number_events and
 resort the events array so that all the active kevents are
 sequential without any closed sockets still in that array?

It occurs to me, you might be trying to use kqueue like select(),
in that you are giving an input queue to every invocation of
kevent(), in the same way that select needs descriptor map
arguments for every invocation.  If that's the case, you don't
need to do this.  You only need to set read events for a
descriptor once.  kevent() will keep returning read events while
the descriptor is open and readable.

--
James Bailie [EMAIL PROTECTED]
http://www.mammothcheese.ca
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Kqueue queries

2007-06-12 Thread James Bailie

Cole wrote:

 If I do the above, and just keep increasing number_events and
 just mark the kevent as EV_DISABLED or EV_DELETE then all it
 does is return that event as soon as I call kevent() with the
 following values:  ident : 7, filter : -1, flags : 16384

That flags value is EV_ERROR.  It indicates your attempt to
register an event on a closed descriptor.  You do not need to
disable or delete events manually if the descriptor is closed,
if that was the intent.  Closing a descriptor causes all events
registered on it to be removed automatically.  You need to get
those events for closed descriptors out of your input queue.

--
James Bailie [EMAIL PROTECTED]
http://www.mammothcheese.ca
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]