From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 12 20:45:25 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id B318716A41F for ; Tue, 12 Jun 2007 20:45:25 +0000 (UTC) (envelope-from cole@opteqint.net) Received: from elektra.opteqint.net (elektra.opteqint.net [209.25.178.105]) by mx1.freebsd.org (Postfix) with ESMTP id 9598C13C4AD for ; Tue, 12 Jun 2007 20:45:25 +0000 (UTC) (envelope-from cole@opteqint.net) Received: from [196.209.59.252] (helo=deadmind) by elektra.opteqint.net with esmtpsa (TLSv1:RC4-MD5:128) (Exim 4.66 (FreeBSD)) (envelope-from ) id 1HyCwZ-000AQk-8M for freebsd-hackers@freebsd.org; Tue, 12 Jun 2007 13:27:07 -0700 From: "Cole" To: Date: Tue, 12 Jun 2007 22:23:51 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2962 Thread-Index: AcetL5aTJyjf2C9TTBKKkTv9I6JwXw== Message-Id: <20070612204525.9598C13C4AD@mx1.freebsd.org> Subject: Kqueue queries X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: cole@opteqint.net List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2007 20:45:25 -0000 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