Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/uipc_socket.c
Show First 20 Lines • Show All 1,055 Lines • ▼ Show 20 Lines | sofree(struct socket *so) | ||||
sodealloc(so); | sodealloc(so); | ||||
} | } | ||||
/* | /* | ||||
* Close a socket on last file table reference removal. Initiate disconnect | * Close a socket on last file table reference removal. Initiate disconnect | ||||
* if connected. Free socket when disconnect complete. | * if connected. Free socket when disconnect complete. | ||||
* | * | ||||
* This function will sorele() the socket. Note that soclose() may be called | * This function will sorele() the socket. Note that soclose() may be called | ||||
* prior to the ref count reaching zero. The actual socket structure will | * prior to the ref count reaching zero. The actual socket structure will | ||||
rwatson: Comment should be a full sentence. | |||||
* not be freed until the ref count reaches zero. | * not be freed until the ref count reaches zero. | ||||
*/ | */ | ||||
int | int | ||||
soclose(struct socket *so) | soclose(struct socket *so) | ||||
{ | { | ||||
struct accept_queue lqueue; | struct accept_queue lqueue; | ||||
bool listening; | bool listening; | ||||
int error = 0; | int error = 0; | ||||
KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter")); | KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter")); | ||||
CURVNET_SET(so->so_vnet); | CURVNET_SET(so->so_vnet); | ||||
funsetown(&so->so_sigio); | funsetown(&so->so_sigio); | ||||
if (so->so_state & SS_ISCONNECTED) { | if (so->so_state & SS_ISCONNECTED) { | ||||
if ((so->so_state & SS_ISDISCONNECTING) == 0) { | if ((so->so_state & SS_ISDISCONNECTING) == 0) { | ||||
error = sodisconnect(so); | error = sodisconnect(so); | ||||
if (error) { | if (error) { | ||||
if (error == ENOTCONN) | if (error == ENOTCONN) | ||||
error = 0; | error = 0; | ||||
goto drop; | goto drop; | ||||
} | } | ||||
} | } | ||||
Done Inline ActionsThis is a second socket-lock acquisition in a row. How can we convince ourselves that this is safe? rwatson: This is a second socket-lock acquisition in a row. How can we convince ourselves that this is… | |||||
Not Done Inline ActionsBy simply re-order the code a bit we can unlock the first one before we lock the other. johalun0_gmail.com: By simply re-order the code a bit we can unlock the first one before we lock the other. | |||||
if (so->so_options & SO_LINGER) { | if (so->so_options & SO_LINGER) { | ||||
if ((so->so_state & SS_ISDISCONNECTING) && | if ((so->so_state & SS_ISDISCONNECTING) && | ||||
(so->so_state & SS_NBIO)) | (so->so_state & SS_NBIO)) | ||||
goto drop; | goto drop; | ||||
while (so->so_state & SS_ISCONNECTED) { | while (so->so_state & SS_ISCONNECTED) { | ||||
error = tsleep(&so->so_timeo, | error = tsleep(&so->so_timeo, | ||||
PSOCK | PCATCH, "soclos", | PSOCK | PCATCH, "soclos", | ||||
so->so_linger * hz); | so->so_linger * hz); | ||||
Show All 33 Lines | if (listening) { | ||||
struct socket *sp; | struct socket *sp; | ||||
TAILQ_FOREACH(sp, &lqueue, so_list) { | TAILQ_FOREACH(sp, &lqueue, so_list) { | ||||
SOCK_LOCK(sp); | SOCK_LOCK(sp); | ||||
if (sp->so_count == 0) { | if (sp->so_count == 0) { | ||||
SOCK_UNLOCK(sp); | SOCK_UNLOCK(sp); | ||||
soabort(sp); | soabort(sp); | ||||
} else | } else | ||||
/* sp is now in sofree() */ | /* sp is now in sofree() */ | ||||
Done Inline ActionsMissing space after "if". rwatson: Missing space after "if". | |||||
SOCK_UNLOCK(sp); | SOCK_UNLOCK(sp); | ||||
} | } | ||||
} | } | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
Done Inline ActionsMissing space after "if". rwatson: Missing space after "if". | |||||
return (error); | return (error); | ||||
Done Inline ActionsMissing space after "if". rwatson: Missing space after "if". | |||||
} | } | ||||
/* | /* | ||||
* soabort() is used to abruptly tear down a connection, such as when a | * soabort() is used to abruptly tear down a connection, such as when a | ||||
* resource limit is reached (listen queue depth exceeded), or if a listen | * resource limit is reached (listen queue depth exceeded), or if a listen | ||||
* socket is closed while there are sockets waiting to be accepted. | * socket is closed while there are sockets waiting to be accepted. | ||||
* | * | ||||
* This interface is tricky, because it is called on an unreferenced socket, | * This interface is tricky, because it is called on an unreferenced socket, | ||||
▲ Show 20 Lines • Show All 1,621 Lines • ▼ Show 20 Lines | if (sopt->sopt_level != SOL_SOCKET) { | ||||
case SO_DEBUG: | case SO_DEBUG: | ||||
case SO_KEEPALIVE: | case SO_KEEPALIVE: | ||||
case SO_DONTROUTE: | case SO_DONTROUTE: | ||||
case SO_USELOOPBACK: | case SO_USELOOPBACK: | ||||
case SO_BROADCAST: | case SO_BROADCAST: | ||||
case SO_REUSEADDR: | case SO_REUSEADDR: | ||||
case SO_REUSEPORT: | case SO_REUSEPORT: | ||||
case SO_REUSEPORT_LB: | |||||
case SO_OOBINLINE: | case SO_OOBINLINE: | ||||
case SO_TIMESTAMP: | case SO_TIMESTAMP: | ||||
case SO_BINTIME: | case SO_BINTIME: | ||||
case SO_NOSIGPIPE: | case SO_NOSIGPIPE: | ||||
case SO_NO_DDP: | case SO_NO_DDP: | ||||
case SO_NO_OFFLOAD: | case SO_NO_OFFLOAD: | ||||
error = sooptcopyin(sopt, &optval, sizeof optval, | error = sooptcopyin(sopt, &optval, sizeof optval, | ||||
sizeof optval); | sizeof optval); | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | case SO_LINGER: | ||||
break; | break; | ||||
case SO_USELOOPBACK: | case SO_USELOOPBACK: | ||||
case SO_DONTROUTE: | case SO_DONTROUTE: | ||||
case SO_DEBUG: | case SO_DEBUG: | ||||
case SO_KEEPALIVE: | case SO_KEEPALIVE: | ||||
case SO_REUSEADDR: | case SO_REUSEADDR: | ||||
case SO_REUSEPORT: | case SO_REUSEPORT: | ||||
case SO_REUSEPORT_LB: | |||||
case SO_BROADCAST: | case SO_BROADCAST: | ||||
case SO_OOBINLINE: | case SO_OOBINLINE: | ||||
case SO_ACCEPTCONN: | case SO_ACCEPTCONN: | ||||
case SO_TIMESTAMP: | case SO_TIMESTAMP: | ||||
case SO_BINTIME: | case SO_BINTIME: | ||||
case SO_NOSIGPIPE: | case SO_NOSIGPIPE: | ||||
optval = so->so_options & sopt->sopt_name; | optval = so->so_options & sopt->sopt_name; | ||||
integer: | integer: | ||||
▲ Show 20 Lines • Show All 1,122 Lines • Show Last 20 Lines |
Comment should be a full sentence.