From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 31 07:32:14 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB39116A4CE for ; Thu, 31 Mar 2005 07:32:14 +0000 (GMT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 66AFD43D41 for ; Thu, 31 Mar 2005 07:32:14 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id j2V7WEAF037127; Thu, 31 Mar 2005 01:32:14 -0600 (CST) (envelope-from dan) Date: Thu, 31 Mar 2005 01:32:13 -0600 From: Dan Nelson To: Matthew Luckie Message-ID: <20050331073213.GE46288@dan.emsphone.com> References: <424BA0B5.2000302@luckie.org.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <424BA0B5.2000302@luckie.org.nz> X-OS: FreeBSD 5.4-PRERELEASE X-message-flag: Outlook Error User-Agent: Mutt/1.5.8i cc: freebsd-hackers@freebsd.org Subject: Re: kqueue and ordinary files X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Mar 2005 07:32:14 -0000 In the last episode (Mar 31), Matthew Luckie said: > Does kqueue signal EOF on an ordinary file when there is nothing left > to read? > > The code at http://www.wand.net.nz/~mjl12/kqfile.c.txt > > cc -Wall -o kqfile kqfile.c > ./kqfile kqueue.c > > doesn't ever get EOF notification as far as i can tell. as in, it > isn't signaled in kevent.flags, nor does kqueue signal the file is > ready for reading and then read(2) return 0. > > ident 3 filter 0xffffffff flags 0x0001 fflags 0x0000 data 128 > read 128 bytes > > how should i detect that the file no longer has anything left to read > with kqueue? at the moment I use select but would like to use kqueue > where available. You can get it indirectly by examining the data field. You can see that the call just before the final kqueue returns data=60, so if your read call returns 60, you're done. The current behaviour is useful for things like tail or syslog watchers, so that they get an EVFILT_READ event when the file grows. They may be better off registering an EVFILT_VNODE/NOTE_EXTEND event though, so you could make a case for returning EV_EOF on EVFILT_READ instead of blocking. -- Dan Nelson dnelson@allantgroup.com