diff options
author | jdp <jdp@FreeBSD.org> | 2001-12-14 22:17:54 +0000 |
---|---|---|
committer | jdp <jdp@FreeBSD.org> | 2001-12-14 22:17:54 +0000 |
commit | 69c3d327d1923296a67d5d0fd2802e63ab16a492 (patch) | |
tree | eeacb40d73299ff032d264a933e2b0b0dc3c2af2 /sys/net/bpfdesc.h | |
parent | 1d5fbcbdb0c947a393f140ca657e2d6561cb89a9 (diff) | |
download | FreeBSD-src-69c3d327d1923296a67d5d0fd2802e63ab16a492.zip FreeBSD-src-69c3d327d1923296a67d5d0fd2802e63ab16a492.tar.gz |
Make bpf's read timeout feature work more correctly with
select/poll, and therefore with pthreads. I doubt there is any way
to make this 100% semantically identical to the way it behaves in
unthreaded programs with blocking reads, but the solution here
should do the right thing for all reasonable usage patterns.
The basic idea is to schedule a callout for the read timeout when a
select/poll is done. When the callout fires, it ends the select if
it is still in progress, or marks the state as "timed out" if the
select has already ended for some other reason. Additional logic in
bpfread then does the right thing in the case where the timeout has
fired.
Note, I co-opted the bd_state member of the bpf_d structure. It has
been present in the structure since the initial import of 4.4-lite,
but as far as I can tell it has never been used.
PR: kern/22063 and bin/31649
MFC after: 3 days
Diffstat (limited to 'sys/net/bpfdesc.h')
-rw-r--r-- | sys/net/bpfdesc.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h index 7f61d70..7db4193 100644 --- a/sys/net/bpfdesc.h +++ b/sys/net/bpfdesc.h @@ -43,6 +43,7 @@ #ifndef _NET_BPFDESC_H_ #define _NET_BPFDESC_H_ +#include <sys/callout.h> #include <sys/selinfo.h> /* @@ -90,8 +91,14 @@ struct bpf_d { struct selinfo bd_sel; /* bsd select info */ #endif struct mtx bd_mtx; /* mutex for this descriptor */ + struct callout bd_callout; /* for BPF timeouts with select */ }; +/* Values for bd_state */ +#define BPF_IDLE 0 /* no select in progress */ +#define BPF_WAITING 1 /* waiting for read timeout in select */ +#define BPF_TIMED_OUT 2 /* read timeout has expired in select */ + #define BPFD_LOCK(bd) mtx_lock(&(bd)->bd_mtx) #define BPFD_UNLOCK(bd) mtx_unlock(&(bd)->bd_mtx) |