In uipc_send() and uipc_rcvd(), store unp->unp_conn pointer in unp2

while working with the second unpcb to make the code more clear.
This commit is contained in:
Robert Watson 2006-07-22 18:41:42 +00:00
parent 1c381b19ff
commit f3f49bbbe8

View File

@ -360,11 +360,11 @@ static int
uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct thread *td) struct mbuf *control, struct thread *td)
{ {
int error = 0; struct unpcb *unp, *unp2;
struct unpcb *unp;
struct socket *so2; struct socket *so2;
u_int mbcnt, sbcc; u_int mbcnt, sbcc;
u_long newhiwat; u_long newhiwat;
int error = 0;
unp = sotounpcb(so); unp = sotounpcb(so);
KASSERT(unp != NULL, ("uipc_send: unp == NULL")); KASSERT(unp != NULL, ("uipc_send: unp == NULL"));
@ -396,12 +396,13 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
break; break;
} }
} }
so2 = unp->unp_conn->unp_socket; unp2 = unp->unp_conn;
so2 = unp2->unp_socket;
if (unp->unp_addr != NULL) if (unp->unp_addr != NULL)
from = (struct sockaddr *)unp->unp_addr; from = (struct sockaddr *)unp->unp_addr;
else else
from = &sun_noname; from = &sun_noname;
if (unp->unp_conn->unp_flags & UNP_WANTCRED) if (unp2->unp_flags & UNP_WANTCRED)
control = unp_addsockcred(td, control); control = unp_addsockcred(td, control);
SOCKBUF_LOCK(&so2->so_rcv); SOCKBUF_LOCK(&so2->so_rcv);
if (sbappendaddr_locked(&so2->so_rcv, from, m, control)) { if (sbappendaddr_locked(&so2->so_rcv, from, m, control)) {
@ -440,16 +441,17 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
error = EPIPE; error = EPIPE;
break; break;
} }
if (unp->unp_conn == NULL) unp2 = unp->unp_conn;
if (unp2 == NULL)
panic("uipc_send connected but no connection?"); panic("uipc_send connected but no connection?");
so2 = unp->unp_conn->unp_socket; so2 = unp2->unp_socket;
SOCKBUF_LOCK(&so2->so_rcv); SOCKBUF_LOCK(&so2->so_rcv);
if (unp->unp_conn->unp_flags & UNP_WANTCRED) { if (unp2->unp_flags & UNP_WANTCRED) {
/* /*
* Credentials are passed only once on * Credentials are passed only once on
* SOCK_STREAM. * SOCK_STREAM.
*/ */
unp->unp_conn->unp_flags &= ~UNP_WANTCRED; unp2->unp_flags &= ~UNP_WANTCRED;
control = unp_addsockcred(td, control); control = unp_addsockcred(td, control);
} }
/* /*
@ -462,20 +464,19 @@ uipc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
} else { } else {
sbappend_locked(&so2->so_rcv, m); sbappend_locked(&so2->so_rcv, m);
} }
mbcnt = so2->so_rcv.sb_mbcnt - unp->unp_conn->unp_mbcnt; mbcnt = so2->so_rcv.sb_mbcnt - unp2->unp_mbcnt;
unp->unp_conn->unp_mbcnt = so2->so_rcv.sb_mbcnt; unp2->unp_mbcnt = so2->so_rcv.sb_mbcnt;
sbcc = so2->so_rcv.sb_cc; sbcc = so2->so_rcv.sb_cc;
sorwakeup_locked(so2); sorwakeup_locked(so2);
SOCKBUF_LOCK(&so->so_snd); SOCKBUF_LOCK(&so->so_snd);
newhiwat = so->so_snd.sb_hiwat - newhiwat = so->so_snd.sb_hiwat - (sbcc - unp2->unp_cc);
(sbcc - unp->unp_conn->unp_cc);
(void)chgsbsize(so->so_cred->cr_uidinfo, &so->so_snd.sb_hiwat, (void)chgsbsize(so->so_cred->cr_uidinfo, &so->so_snd.sb_hiwat,
newhiwat, RLIM_INFINITY); newhiwat, RLIM_INFINITY);
so->so_snd.sb_mbmax -= mbcnt; so->so_snd.sb_mbmax -= mbcnt;
SOCKBUF_UNLOCK(&so->so_snd); SOCKBUF_UNLOCK(&so->so_snd);
unp->unp_conn->unp_cc = sbcc; unp2->unp_cc = sbcc;
m = NULL; m = NULL;
break; break;