From owner-freebsd-arch@FreeBSD.ORG Fri Nov 21 01:27:45 2003 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 822E716A4CE; Fri, 21 Nov 2003 01:27:45 -0800 (PST) Received: from eth0.b.smtp.sonic.net (eth0.b.smtp.sonic.net [64.142.19.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id B520543FE3; Fri, 21 Nov 2003 01:27:44 -0800 (PST) (envelope-from gharris@sonic.net) Received: from quadrajet.sonic.net (adsl-209-204-185-249.sonic.net [209.204.185.249])hAL9Rgni008972; Fri, 21 Nov 2003 01:27:43 -0800 Received: (from guy@localhost) by quadrajet.sonic.net (8.9.3/8.9.3) id BAA52399; Fri, 21 Nov 2003 01:27:41 -0800 (PST) (envelope-from gharris) Date: Fri, 21 Nov 2003 01:27:41 -0800 From: Guy Harris To: Bruce Evans Message-ID: <20031121012741.G329@quadrajet.sonic.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i cc: arch@FreeBSD.org cc: fenner@FreeBSD.org Subject: Re: bpf/pcap are weird X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Nov 2003 09:27:45 -0000 > > bpfpoll() is reported to be broken; see PR 36219. > > Yes, that's the PR that indicated that "select()"/"poll()" don't, in > fact, work correctly with timeouts. > > That was fixed in 4.5... > > > Rev.1.113 of bpf.c may have disturbed this. > > ...but might have been re-broken. > > > It removed the comment which said that > > bpf_ready() doesn't acually imitate resultof(FIONREAD) != 0. > > ...and it also removed the check for "d->bd_state == BPF_TIMED_OUT" that > made "select()"/"poll()" work with timeouts. I didn't read the code fully - no, it didn't. Revision 1.113 changed if (events & (POLLIN | POLLRDNORM)) { /* * An imitation of the FIONREAD ioctl code. * XXX not quite. An exact imitation: * if (d->b_slen != 0 || * (d->bd_hbuf != NULL && d->bd_hlen != 0) */ if (d->bd_hlen != 0 || ((d->bd_immediate || d->bd_state == BPF_TIMED_OUT) && d->bd_slen != 0)) revents |= events & (POLLIN | POLLRDNORM); else { selrecord(td, &d->bd_sel); /* Start the read timeout if necessary. */ if (d->bd_rtout > 0 && d->bd_state == BPF_IDLE) { callout_reset(&d->bd_callout, d->bd_rtout, bpf_timed_out, d); d->bd_state = BPF_WAITING; } } } to if (events & (POLLIN | POLLRDNORM)) { if (bpf_ready(d)) revents |= events & (POLLIN | POLLRDNORM); else { selrecord(td, &d->bd_sel); /* Start the read timeout if necessary. */ if (d->bd_rtout > 0 && d->bd_state == BPF_IDLE) { callout_reset(&d->bd_callout, d->bd_rtout, bpf_timed_out, d); d->bd_state = BPF_WAITING; } } } but revision 1.23 of "bpfdesc.h" introduce a macro "bpf_ready(bd)" that does #define bpf_ready(bd) \ ((bd)->bd_hlen != 0 || \ (((bd)->bd_immediate || (bd)->bd_state == BPF_TIMED_OUT) && \ (bd)->bd_slen != 0)) so the actual "bpf_poll()" code doesn't change. Revision 1.23 was MFC'ed to the 4.x branch in revision 1.14.2.3, which is in 4.9. (Also, the problem I mentioned with FreeBSD 4.4 not supporting the workaround for "select()" not working is in FreeBSD 4.3 as well.)