Date: Mon, 22 Mar 2010 20:26:52 +0000 (UTC) From: Jung-uk Kim <jkim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org Subject: svn commit: r205467 - stable/6/sys/net Message-ID: <201003222026.o2MKQqbt030921@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jkim Date: Mon Mar 22 20:26:52 2010 New Revision: 205467 URL: http://svn.freebsd.org/changeset/base/205467 Log: MFC: r204105 Return partially filled buffer for non-blocking read(2) in non-immediate mode. PR: kern/143855 Submitted by: Guy Harris (guy at alum dot mit dot edu) Modified: stable/6/sys/net/bpf.c Directory Properties: stable/6/sys/ (props changed) stable/6/sys/contrib/pf/ (props changed) stable/6/sys/dev/cxgb/ (props changed) Modified: stable/6/sys/net/bpf.c ============================================================================== --- stable/6/sys/net/bpf.c Mon Mar 22 20:24:00 2010 (r205466) +++ stable/6/sys/net/bpf.c Mon Mar 22 20:26:52 2010 (r205467) @@ -456,8 +456,9 @@ static int bpfread(struct cdev *dev, struct uio *uio, int ioflag) { struct bpf_d *d = dev->si_drv1; - int timed_out; int error; + int non_block; + int timed_out; /* * Restrict application to use a buffer the same size as @@ -466,6 +467,8 @@ bpfread(struct cdev *dev, struct uio *ui if (uio->uio_resid != d->bd_bufsize) return (EINVAL); + non_block = ((ioflag & O_NONBLOCK) != 0); + BPFD_LOCK(d); d->bd_pid = curthread->td_proc->p_pid; if (d->bd_state == BPF_WAITING) @@ -478,14 +481,20 @@ bpfread(struct cdev *dev, struct uio *ui * have arrived to fill the store buffer. */ while (d->bd_hbuf == NULL) { - if ((d->bd_immediate || timed_out) && d->bd_slen != 0) { + if (d->bd_slen != 0) { /* * A packet(s) either arrived since the previous * read or arrived while we were asleep. - * Rotate the buffers and return what's here. */ - ROTATE_BUFFERS(d); - break; + if (d->bd_immediate || non_block || timed_out) { + /* + * Rotate the buffers and return what's here + * if we are in immediate mode, non-blocking + * flag is set, or this descriptor timed out. + */ + ROTATE_BUFFERS(d); + break; + } } /* @@ -499,7 +508,7 @@ bpfread(struct cdev *dev, struct uio *ui return (ENXIO); } - if (ioflag & O_NONBLOCK) { + if (non_block) { BPFD_UNLOCK(d); return (EWOULDBLOCK); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003222026.o2MKQqbt030921>