On Friday, November 09, 2001 5:56 AM Edwin Groothuis [EMAIL PROTECTED] wrote:
> 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? The problem is probably due to the poll system call that the threaded library does before performing the read(). In the non-threaded case, the read() returns when the timeout is hit; in the threaded case, the threaded library's poll() has to succeed before the read system call will be executed, and poll() won't succeed until the buffer is full. If you would like to try this patch (relative to FreeBSD 4.3) to /sys/net/bpf.c and /sys/net/bpfdesc.h and let me know if it helps, I will add this patch to PR 22063 and perhaps commit it if it passes review. Guy Helmer
bpf-new.diff
Description: Binary data