Date: Tue, 12 Jun 2007 22:23:51 +0200 From: "Cole" <cole@opteqint.net> To: <freebsd-hackers@freebsd.org> Subject: Kqueue queries Message-ID: <20070612204525.9598C13C4AD@mx1.freebsd.org>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070612204525.9598C13C4AD>