From owner-freebsd-hackers Fri Nov 9 3:56: 0 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from topaz.mdcc.cx (topaz.mdcc.cx [212.204.230.141]) by hub.freebsd.org (Postfix) with ESMTP id BC00237B41D for ; Fri, 9 Nov 2001 03:55:57 -0800 (PST) Received: from k7.mavetju.org (topaz.mdcc.cx [212.204.230.141]) by topaz.mdcc.cx (Postfix) with ESMTP id 641242B74A for ; Fri, 9 Nov 2001 12:55:48 +0100 (CET) Received: by k7.mavetju.org (Postfix, from userid 1001) id F0D9A126; Fri, 9 Nov 2001 22:55:33 +1100 (EST) Date: Fri, 9 Nov 2001 22:55:32 +1100 From: Edwin Groothuis To: freebsd-hackers@freebsd.org Subject: pcap/bpf in a multi-threaded environment Message-ID: <20011109225532.A3919@k7.mavetju.org> Mail-Followup-To: Edwin Groothuis , freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Greetings, The past couple of days I've been plagued by a strange behaviour of something between libpcap and the bpf-device. As you can read in PR bin/31649, the behaviour of libpcap is very different if you compile it on gcc with or without -pthread: Without -pthread, it calls the callback function everytime it has received a packet. With -pthread, it calls the callback function only when the input-buffer (about 32Kb) is nearly full. I've done some investigation (with my limited knowledge of what happens between a call to read() and when it ends up in bpfread()) and saw the difference between a call with and without the -pthreads option: in /usr/src/contrib/libpcap/pcap-bpf.c, line 81, the function pcap_read(): cc = read(p->fd, (char *)p->buffer, p->bufsize); at a certain moment, in the read()-code, bpfread() is called: /sys/net/bpf.c, line 491 In a non-threaded environment, this if-statement is false if (ioflag & IO_NDELAY) { splx(s); return (EWOULDBLOCK); } In a threaded environment, the if-statement is true, splx(s) is called and EWOULDBLOCK is returned. Then it's silent for a while, while the packets are being collected (somewhere) and at a certain moment the buffer is nearly full and the read() in pcap_read() is finished. So yeah, I'm stuck. All I want is in threaded mode to have the same behaviour as I have in non-threaded mode. Anybody any ideas on how to fix this? Thanks in advance, Edwin -- Edwin Groothuis | Personal website: http://www.MavEtJu.org edwin@mavetju.org | Interested in MUDs? Visit Fatal Dimensions: ------------------+ http://www.FatalDimensions.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message