From owner-freebsd-hackers Sat Jul 3 8:44:22 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from sumatra.americantv.com (sumatra.americantv.com [208.139.222.227]) by hub.freebsd.org (Postfix) with ESMTP id DDC3B14CCE for ; Sat, 3 Jul 1999 08:44:16 -0700 (PDT) (envelope-from jlemon@americantv.com) Received: from right.PCS (right.PCS [148.105.10.31]) by sumatra.americantv.com (8.8.5/8.8.5) with ESMTP id KAA26627; Sat, 3 Jul 1999 10:44:13 -0500 (CDT) Received: (from jlemon@localhost) by right.PCS (8.6.13/8.6.4) id KAA19656; Sat, 3 Jul 1999 10:44:12 -0500 Message-ID: <19990703104412.48991@right.PCS> Date: Sat, 3 Jul 1999 10:44:12 -0500 From: Jonathan Lemon To: "Brian F. Feldman" Cc: wayne@crb-web.com, hackers@FreeBSD.ORG Subject: Re: poll() vs select() References: <19990703083935.61252@right.PCS> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.61.1 In-Reply-To: ; from Brian F. Feldman on Jul 07, 1999 at 11:27:57AM -0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Jul 07, 1999 at 11:27:57AM -0400, Brian F. Feldman wrote: > On Sat, 3 Jul 1999, Jonathan Lemon wrote: > > > On Jul 07, 1999 at 01:01:07AM -0400, Brian F. Feldman wrote: > > > On Fri, 2 Jul 1999, Jonathan Lemon wrote: > > > > > > As for new code, use whichever you are comfortable with. Personally, I > > > > would recommend poll(), since it provides some added functionality over > > > > select() that makes for easier programming. > > > > > > poll() is a huge pain to use, which is why I recommend select(). > > > > Whichever you're comfortable with. poll() isn't a pain once you know > > how to use it, and it does bring additional benefits. > > I don't see how you can not find poll() a pain when compared to select(). It > requires so much set-up, much like (for instance) aio_write() as opposed to > write(). I suppose if you're masochistic, you won't mind doing that :) Yes, it does require more initial setup. But consider: - you don't have to re-initialize the fd sets every time around the loop, as you do with select(). This administrative overhead is moved into the initial setup, not into the main loop. - it becomes simple to ignore a slot entry; simply set the fd value to -1. - you get notification when the fd is closed. E.g.: you can poll() on a fd, ignoring both read ready and write ready state, and get POLLHUP returned when it closes. for select(), the only way to know that the fd closed is to actually do a read() on the descriptor, and have it return EOF. -- Jonathan To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message