svn commit: r204341 - stable/8/sys/net
Jung-uk Kim
jkim at FreeBSD.org
Fri Feb 26 00:11:18 UTC 2010
Author: jkim
Date: Fri Feb 26 00:11:17 2010
New Revision: 204341
URL: http://svn.freebsd.org/changeset/base/204341
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/8/sys/net/bpf.c
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/amd64/include/xen/ (props changed)
stable/8/sys/cddl/contrib/opensolaris/ (props changed)
stable/8/sys/contrib/dev/acpica/ (props changed)
stable/8/sys/contrib/pf/ (props changed)
stable/8/sys/dev/xen/xenpci/ (props changed)
stable/8/sys/netinet/ (props changed)
Modified: stable/8/sys/net/bpf.c
==============================================================================
--- stable/8/sys/net/bpf.c Thu Feb 25 22:44:23 2010 (r204340)
+++ stable/8/sys/net/bpf.c Fri Feb 26 00:11:17 2010 (r204341)
@@ -661,8 +661,9 @@ static int
bpfread(struct cdev *dev, struct uio *uio, int ioflag)
{
struct bpf_d *d;
- int timed_out;
int error;
+ int non_block;
+ int timed_out;
error = devfs_get_cdevpriv((void **)&d);
if (error != 0)
@@ -675,6 +676,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_bufmode != BPF_BUFMODE_BUFFER) {
@@ -691,14 +694,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;
+ }
}
/*
@@ -712,7 +721,7 @@ bpfread(struct cdev *dev, struct uio *ui
return (ENXIO);
}
- if (ioflag & O_NONBLOCK) {
+ if (non_block) {
BPFD_UNLOCK(d);
return (EWOULDBLOCK);
}
More information about the svn-src-stable-8
mailing list