version 1.36, 1998/07/31 22:50:52 |
version 1.41, 1999/01/20 09:15:41 |
|
|
#include <sys/socketvar.h> |
#include <sys/socketvar.h> |
#include <sys/signalvar.h> |
#include <sys/signalvar.h> |
#include <sys/resourcevar.h> |
#include <sys/resourcevar.h> |
|
#include <sys/pool.h> |
|
|
|
struct pool socket_pool; |
|
|
|
void |
|
soinit() |
|
{ |
|
|
|
pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0, |
|
"sockpl", 0, NULL, NULL, M_SOCKET); |
|
} |
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
Line 70 socreate(dom, aso, type, proto) |
|
Line 81 socreate(dom, aso, type, proto) |
|
register struct protosw *prp; |
register struct protosw *prp; |
register struct socket *so; |
register struct socket *so; |
register int error; |
register int error; |
|
int s; |
|
|
if (proto) |
if (proto) |
prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
Line 79 socreate(dom, aso, type, proto) |
|
Line 91 socreate(dom, aso, type, proto) |
|
return (EPROTONOSUPPORT); |
return (EPROTONOSUPPORT); |
if (prp->pr_type != type) |
if (prp->pr_type != type) |
return (EPROTOTYPE); |
return (EPROTOTYPE); |
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); |
s = splsoftnet(); |
bzero((caddr_t)so, sizeof(*so)); |
so = pool_get(&socket_pool, PR_WAITOK); |
|
memset((caddr_t)so, 0, sizeof(*so)); |
TAILQ_INIT(&so->so_q0); |
TAILQ_INIT(&so->so_q0); |
TAILQ_INIT(&so->so_q); |
TAILQ_INIT(&so->so_q); |
so->so_type = type; |
so->so_type = type; |
Line 92 socreate(dom, aso, type, proto) |
|
Line 105 socreate(dom, aso, type, proto) |
|
if (error) { |
if (error) { |
so->so_state |= SS_NOFDREF; |
so->so_state |= SS_NOFDREF; |
sofree(so); |
sofree(so); |
|
splx(s); |
return (error); |
return (error); |
} |
} |
#ifdef COMPAT_SUNOS |
#ifdef COMPAT_SUNOS |
Line 101 socreate(dom, aso, type, proto) |
|
Line 115 socreate(dom, aso, type, proto) |
|
so->so_options |= SO_BROADCAST; |
so->so_options |= SO_BROADCAST; |
} |
} |
#endif |
#endif |
|
splx(s); |
*aso = so; |
*aso = so; |
return (0); |
return (0); |
} |
} |
|
|
register struct socket *so; |
register struct socket *so; |
{ |
{ |
|
|
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
/* |
|
* We must not decommission a socket that's on the accept(2) queue. |
|
* If we do, then accept(2) may hang even after select(2) indicated |
|
* that the listening socket was ready. |
|
*/ |
|
if (so->so_pcb || so->so_head || (so->so_state & SS_NOFDREF) == 0) |
return; |
return; |
if (so->so_head) { |
|
if (!soqremque(so, 0) && !soqremque(so, 1)) |
|
panic("sofree dq"); |
|
so->so_head = 0; |
|
} |
|
sbrelease(&so->so_snd); |
sbrelease(&so->so_snd); |
sorflush(so); |
sorflush(so); |
FREE(so, M_SOCKET); |
pool_put(&socket_pool, so); |
} |
} |
|
|
/* |
/* |
|
|
soclose(so) |
soclose(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |
|
struct socket *so2; |
int s = splsoftnet(); /* conservative */ |
int s = splsoftnet(); /* conservative */ |
int error = 0; |
int error = 0; |
|
|
if (so->so_options & SO_ACCEPTCONN) { |
if (so->so_options & SO_ACCEPTCONN) { |
while (so->so_q0.tqh_first) |
while ((so2 = so->so_q0.tqh_first) != 0) { |
(void) soabort(so->so_q0.tqh_first); |
so2->so_head = 0; |
while (so->so_q.tqh_first) |
(void) soabort(so2); |
(void) soabort(so->so_q.tqh_first); |
} |
|
while ((so2 = so->so_q.tqh_first) != 0) { |
|
so2->so_head = 0; |
|
(void) soabort(so2); |
|
} |
} |
} |
if (so->so_pcb == 0) |
if (so->so_pcb == 0) |
goto discard; |
goto discard; |
Line 238 soaccept(so, nam) |
|
Line 258 soaccept(so, nam) |
|
if ((so->so_state & SS_NOFDREF) == 0) |
if ((so->so_state & SS_NOFDREF) == 0) |
panic("soaccept: !NOFDREF"); |
panic("soaccept: !NOFDREF"); |
so->so_state &= ~SS_NOFDREF; |
so->so_state &= ~SS_NOFDREF; |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, (struct mbuf *)0, |
if ((so->so_state & SS_ISDISCONNECTED) == 0) |
nam, (struct mbuf *)0, (struct proc *)0); |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, |
|
(struct mbuf *)0, nam, (struct mbuf *)0, (struct proc *)0); |
|
else |
|
error = 0; |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
|
|
} while (space > 0 && atomic); |
} while (space > 0 && atomic); |
if (dontroute) |
if (dontroute) |
so->so_options |= SO_DONTROUTE; |
so->so_options |= SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state |= SS_MORETOCOME; |
s = splsoftnet(); /* XXX */ |
s = splsoftnet(); /* XXX */ |
error = (*so->so_proto->pr_usrreq)(so, |
error = (*so->so_proto->pr_usrreq)(so, |
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
|
|
splx(s); |
splx(s); |
if (dontroute) |
if (dontroute) |
so->so_options &= ~SO_DONTROUTE; |
so->so_options &= ~SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state &= ~SS_MORETOCOME; |
clen = 0; |
clen = 0; |
control = 0; |
control = 0; |
top = 0; |
top = 0; |
|
|
socantrcvmore(so); |
socantrcvmore(so); |
sbunlock(sb); |
sbunlock(sb); |
asb = *sb; |
asb = *sb; |
bzero((caddr_t)sb, sizeof(*sb)); |
memset((caddr_t)sb, 0, sizeof(*sb)); |
splx(s); |
splx(s); |
if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose) |
if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose) |
(*pr->pr_domain->dom_dispose)(asb.sb_mb); |
(*pr->pr_domain->dom_dispose)(asb.sb_mb); |