diff options
author | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
---|---|---|
committer | tanimura <tanimura@FreeBSD.org> | 2002-05-20 05:41:09 +0000 |
commit | 92d8381dd544a8237b3fd68c4e7fce9bd0903fb2 (patch) | |
tree | 2465ddbcecac65f96c5c6d5cef1a4fe3f1ac03f8 /sys/netinet/accf_http.c | |
parent | 969293170b27461145f69a538d5abd15fea34ba1 (diff) | |
download | FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.zip FreeBSD-src-92d8381dd544a8237b3fd68c4e7fce9bd0903fb2.tar.gz |
Lock down a socket, milestone 1.
o Add a mutex (sb_mtx) to struct sockbuf. This protects the data in a
socket buffer. The mutex in the receive buffer also protects the data
in struct socket.
o Determine the lock strategy for each members in struct socket.
o Lock down the following members:
- so_count
- so_options
- so_linger
- so_state
o Remove *_locked() socket APIs. Make the following socket APIs
touching the members above now require a locked socket:
- sodisconnect()
- soisconnected()
- soisconnecting()
- soisdisconnected()
- soisdisconnecting()
- sofree()
- soref()
- sorele()
- sorwakeup()
- sotryfree()
- sowakeup()
- sowwakeup()
Reviewed by: alfred
Diffstat (limited to 'sys/netinet/accf_http.c')
-rw-r--r-- | sys/netinet/accf_http.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/sys/netinet/accf_http.c b/sys/netinet/accf_http.c index 4a3e17e..4849f6b 100644 --- a/sys/netinet/accf_http.c +++ b/sys/netinet/accf_http.c @@ -31,7 +31,9 @@ #include <sys/param.h> #include <sys/kernel.h> +#include <sys/lock.h> #include <sys/mbuf.h> +#include <sys/mutex.h> #include <sys/signalvar.h> #include <sys/sysctl.h> #include <sys/socketvar.h> @@ -160,11 +162,13 @@ static void sohashttpget(struct socket *so, void *arg, int waitflag) { + SOCK_LOCK(so); if ((so->so_state & SS_CANTRCVMORE) == 0 && !sbfull(&so->so_rcv)) { struct mbuf *m; char *cmp; int cmplen, cc; + SOCK_UNLOCK(so); m = so->so_rcv.sb_mb; cc = so->so_rcv.sb_cc - 1; if (cc < 1) @@ -197,13 +201,16 @@ sohashttpget(struct socket *so, void *arg, int waitflag) return; } DPRINT("mbufstrcmp bad"); - } + } else + SOCK_UNLOCK(so); fallout: DPRINT("fallout"); + SOCK_LOCK(so); so->so_upcall = NULL; so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected_locked(so); + soisconnected(so); + SOCK_UNLOCK(so); return; } @@ -213,8 +220,12 @@ soparsehttpvers(struct socket *so, void *arg, int waitflag) struct mbuf *m, *n; int i, cc, spaces, inspaces; - if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv)) + SOCK_LOCK(so); + if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv)) { + SOCK_UNLOCK(so); goto fallout; + } + SOCK_UNLOCK(so); m = so->so_rcv.sb_mb; cc = so->so_rcv.sb_cc; @@ -283,9 +294,11 @@ readmore: fallout: DPRINT("fallout"); + SOCK_LOCK(so); so->so_upcall = NULL; so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected_locked(so); + soisconnected(so); + SOCK_UNLOCK(so); return; } @@ -300,8 +313,12 @@ soishttpconnected(struct socket *so, void *arg, int waitflag) int ccleft, copied; DPRINT("start"); - if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv)) + SOCK_LOCK(so); + if ((so->so_state & SS_CANTRCVMORE) != 0 || sbfull(&so->so_rcv)) { + SOCK_UNLOCK(so); goto gotit; + } + SOCK_UNLOCK(so); /* * Walk the socketbuffer and copy the last NCHRS (3) into a, b, and c @@ -353,8 +370,10 @@ readmore: return; gotit: + SOCK_LOCK(so); so->so_upcall = NULL; so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected_locked(so); + soisconnected(so); + SOCK_UNLOCK(so); return; } |