uipc_socket.c (14093) | uipc_socket.c (14547) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 |
34 * $Id: uipc_socket.c,v 1.13 1995/12/14 22:51:01 bde Exp $ | 34 * $Id: uipc_socket.c,v 1.15 1996/02/13 18:16:20 wollman Exp $ |
35 */ 36 37#include <sys/param.h> | 35 */ 36 37#include <sys/param.h> |
38#include <sys/queue.h> |
|
38#include <sys/systm.h> 39#include <sys/proc.h> 40#include <sys/file.h> 41#include <sys/malloc.h> 42#include <sys/mbuf.h> 43#include <sys/domain.h> 44#include <sys/kernel.h> 45#include <sys/protosw.h> --- 31 unchanged lines hidden (view full) --- 77 else 78 prp = pffindtype(dom, type); 79 if (prp == 0 || prp->pr_usrreq == 0) 80 return (EPROTONOSUPPORT); 81 if (prp->pr_type != type) 82 return (EPROTOTYPE); 83 MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); 84 bzero((caddr_t)so, sizeof(*so)); | 39#include <sys/systm.h> 40#include <sys/proc.h> 41#include <sys/file.h> 42#include <sys/malloc.h> 43#include <sys/mbuf.h> 44#include <sys/domain.h> 45#include <sys/kernel.h> 46#include <sys/protosw.h> --- 31 unchanged lines hidden (view full) --- 78 else 79 prp = pffindtype(dom, type); 80 if (prp == 0 || prp->pr_usrreq == 0) 81 return (EPROTONOSUPPORT); 82 if (prp->pr_type != type) 83 return (EPROTOTYPE); 84 MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); 85 bzero((caddr_t)so, sizeof(*so)); |
86 TAILQ_INIT(&so->so_incomp); 87 TAILQ_INIT(&so->so_comp); |
|
85 so->so_type = type; 86 if (p->p_ucred->cr_uid == 0) 87 so->so_state = SS_PRIV; 88 so->so_proto = prp; 89 error = 90 (*prp->pr_usrreq)(so, PRU_ATTACH, 91 (struct mbuf *)0, (struct mbuf *)proto, (struct mbuf *)0); 92 if (error) { --- 29 unchanged lines hidden (view full) --- 122 123 error = 124 (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, 125 (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); 126 if (error) { 127 splx(s); 128 return (error); 129 } | 88 so->so_type = type; 89 if (p->p_ucred->cr_uid == 0) 90 so->so_state = SS_PRIV; 91 so->so_proto = prp; 92 error = 93 (*prp->pr_usrreq)(so, PRU_ATTACH, 94 (struct mbuf *)0, (struct mbuf *)proto, (struct mbuf *)0); 95 if (error) { --- 29 unchanged lines hidden (view full) --- 125 126 error = 127 (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, 128 (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); 129 if (error) { 130 splx(s); 131 return (error); 132 } |
130 if (so->so_q == 0) | 133 if (so->so_comp.tqh_first == NULL) |
131 so->so_options |= SO_ACCEPTCONN; 132 if (backlog < 0 || backlog > somaxconn) 133 backlog = somaxconn; 134 so->so_qlimit = backlog; 135 splx(s); 136 return (0); 137} 138 139void 140sofree(so) 141 register struct socket *so; 142{ | 134 so->so_options |= SO_ACCEPTCONN; 135 if (backlog < 0 || backlog > somaxconn) 136 backlog = somaxconn; 137 so->so_qlimit = backlog; 138 splx(s); 139 return (0); 140} 141 142void 143sofree(so) 144 register struct socket *so; 145{ |
146 struct socket *head = so->so_head; |
|
143 144 if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) 145 return; | 147 148 if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) 149 return; |
146 if (so->so_head) { 147 if (!soqremque(so, 0) && !soqremque(so, 1)) 148 panic("sofree dq"); 149 so->so_head = 0; | 150 if (head != NULL) { 151 if (so->so_state & SS_INCOMP) { 152 TAILQ_REMOVE(&head->so_incomp, so, so_list); 153 } else if (so->so_state & SS_COMP) { 154 TAILQ_REMOVE(&head->so_comp, so, so_list); 155 } else { 156 panic("sofree: not queued"); 157 } 158 head->so_qlen--; 159 so->so_state &= ~(SS_INCOMP|SS_COMP); 160 so->so_head = NULL; |
150 } 151 sbrelease(&so->so_snd); 152 sorflush(so); 153 FREE(so, M_SOCKET); 154} 155 156/* 157 * Close a socket on last file table reference removal. 158 * Initiate disconnect if connected. 159 * Free socket when disconnect complete. 160 */ 161int 162soclose(so) 163 register struct socket *so; 164{ 165 int s = splnet(); /* conservative */ 166 int error = 0; 167 168 if (so->so_options & SO_ACCEPTCONN) { | 161 } 162 sbrelease(&so->so_snd); 163 sorflush(so); 164 FREE(so, M_SOCKET); 165} 166 167/* 168 * Close a socket on last file table reference removal. 169 * Initiate disconnect if connected. 170 * Free socket when disconnect complete. 171 */ 172int 173soclose(so) 174 register struct socket *so; 175{ 176 int s = splnet(); /* conservative */ 177 int error = 0; 178 179 if (so->so_options & SO_ACCEPTCONN) { |
169 while (so->so_q0) 170 (void) soabort(so->so_q0); 171 while (so->so_q) 172 (void) soabort(so->so_q); | 180 struct socket *sp; 181 182 for (sp = so->so_incomp.tqh_first; sp != NULL; sp = sp->so_list.tqe_next) 183 (void) soabort(sp); 184 for (sp = so->so_comp.tqh_first; sp != NULL; sp = sp->so_list.tqe_next) 185 (void) soabort(sp); |
173 } 174 if (so->so_pcb == 0) 175 goto discard; 176 if (so->so_state & SS_ISCONNECTED) { 177 if ((so->so_state & SS_ISDISCONNECTING) == 0) { 178 error = sodisconnect(so); 179 if (error) 180 goto drop; --- 888 unchanged lines hidden --- | 186 } 187 if (so->so_pcb == 0) 188 goto discard; 189 if (so->so_state & SS_ISCONNECTED) { 190 if ((so->so_state & SS_ISDISCONNECTING) == 0) { 191 error = sodisconnect(so); 192 if (error) 193 goto drop; --- 888 unchanged lines hidden --- |