From 02670acd63473f06aa8fd30fa422a7dd8a6fd257 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 20 Dec 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-12-20 --- ip/devip.c | 27 +++++++++++++++++++-------- ip/esp.c | 2 -- ip/gre.c | 2 -- ip/icmp.c | 1 - ip/il.c | 1 - ip/ip.h | 1 + ip/ipifc.c | 14 ++++---------- ip/ipmux.c | 2 -- ip/rudp.c | 1 - ip/tcp.c | 30 ++++++++++++------------------ ip/udp.c | 12 +++++------- port/error.h | 1 + 12 files changed, 42 insertions(+), 52 deletions(-) diff --git a/ip/devip.c b/ip/devip.c index 256b2fe31539f8d2dfbbeb07ddb69cd3fc059eac..a62b266e71476efbda0bdc0dd161dce38ecb19f2 100644 --- a/ip/devip.c +++ b/ip/devip.c @@ -501,8 +501,9 @@ closeconv(Conv *cv) while((mp = cv->multi) != nil) ipifcremmulti(cv, mp->ma, mp->ia); - /* The close routine will unlock the conv */ cv->p->close(cv); + cv->state = Idle; + qunlock(cv); } static void @@ -789,6 +790,8 @@ connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb) { char *p; + if(c->state != 0) + error(Econinuse); c->state = Connecting; c->cerr[0] = '\0'; if(x->connect == nil) @@ -796,7 +799,11 @@ connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb) p = x->connect(c, cb->f, cb->nf); if(p != nil) error(p); + qunlock(c); + sleep(&c->cr, connected, c); + + qlock(c); if(c->cerr[0] != '\0') error(c->cerr); } @@ -830,6 +837,8 @@ announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb) { char *p; + if(c->state != 0) + error(Econinuse); c->state = Announcing; c->cerr[0] = '\0'; if(x->announce == nil) @@ -837,7 +846,11 @@ announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb) p = x->announce(c, cb->f, cb->nf); if(p != nil) error(p); + qunlock(c); + sleep(&c->cr, announced, c); + + qlock(c); if(c->cerr[0] != '\0') error(c->cerr); } @@ -934,12 +947,9 @@ ipwrite(Chan* ch, void *v, long n, vlong off) c = x->conv[CONV(ch->qid)]; cb = parsecmd(a, n); - if(canqlock(&c->car) == 0){ - free(cb); - error("connect/announce in progress"); - } + qlock(c); if(waserror()) { - qunlock(&c->car); + qunlock(c); free(cb); nexterror(); } @@ -983,7 +993,7 @@ ipwrite(Chan* ch, void *v, long n, vlong off) error(p); } else error("unknown control request"); - qunlock(&c->car); + qunlock(c); free(cb); poperror(); } @@ -1129,7 +1139,7 @@ retry: c->inuse = 1; strcpy(c->owner, user); c->perm = 0660; - c->state = 0; + c->state = Idle; ipmove(c->laddr, IPnoaddr); ipmove(c->raddr, IPnoaddr); c->lport = 0; @@ -1211,6 +1221,7 @@ Fsnewcall(Conv *c, uchar *raddr, ushort rport, uchar *laddr, ushort lport) nc->lport = lport; nc->next = nil; *l = nc; + c->state = Connected; qunlock(c); wakeup(&c->listenr); diff --git a/ip/esp.c b/ip/esp.c index 399c91b0ece921087bb55fcef763977289bc2149..6f5703a28eaf1cd70150a288e8ccc743cec00af7 100644 --- a/ip/esp.c +++ b/ip/esp.c @@ -219,8 +219,6 @@ espclose(Conv *c) free(ecb->espstate); free(ecb->ahstate); memset(ecb, 0, sizeof(Espcb)); - - qunlock(c); } void diff --git a/ip/gre.c b/ip/gre.c index 50b4036cfc40eed0902a60e339bccad8ec4aa084..6ff233424dd8967c44a1fb91994258a57cac1f95 100644 --- a/ip/gre.c +++ b/ip/gre.c @@ -114,8 +114,6 @@ greclose(Conv *c) ipmove(c->raddr, IPnoaddr); c->lport = 0; c->rport = 0; - - qunlock(c); } int drop; diff --git a/ip/icmp.c b/ip/icmp.c index 3285e615b03eec696f6059d7181c866ad5919a08..9b2fb4f8a7a58400aadb15c507b0d6b1613f2db7 100644 --- a/ip/icmp.c +++ b/ip/icmp.c @@ -145,7 +145,6 @@ icmpclose(Conv *c) ipmove(c->laddr, IPnoaddr); ipmove(c->raddr, IPnoaddr); c->lport = 0; - qunlock(c); } static void diff --git a/ip/il.c b/ip/il.c index facf2425cf2b057fa9f7656a24dc9c66977e4be4..e5944b1c2f195f98b90bb3d3e2b43e0315ec1a34 100644 --- a/ip/il.c +++ b/ip/il.c @@ -304,7 +304,6 @@ ilclose(Conv *c) break; } ilfreeq(ic); - qunlock(c); } void diff --git a/ip/ip.h b/ip/ip.h index f6cc73df1d13403f925d8fa9f061486736ffef72..e3cfc02273e7b2882f9565d554531087563efa9a 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -48,6 +48,7 @@ enum enum { + Idle= 0, Announcing= 1, Announced= 2, Connecting= 3, diff --git a/ip/ipifc.c b/ip/ipifc.c index a4dc34097654f33d45a08d5281df692d2a4591f0..54e18eb001bc3177c9e0ff836e2f433185f83a0e 100644 --- a/ip/ipifc.c +++ b/ip/ipifc.c @@ -99,7 +99,7 @@ ipfindmedium(char *name) /* * attach a device (or pkt driver) to the interface. - * called with c->car locked + * called with c locked */ static char* ipifcbind(Conv *c, char **argv, int argc) @@ -136,11 +136,8 @@ ipifcbind(Conv *c, char **argv, int argc) ifc->m = m; ifc->minmtu = ifc->m->minmtu; ifc->maxmtu = ifc->m->maxmtu; - if(ifc->m->unbindonclose == 0){ - qlock(ifc->conv); + if(ifc->m->unbindonclose == 0) ifc->conv->inuse++; - qunlock(ifc->conv); - } ifc->ifcid++; wunlock(ifc); @@ -151,6 +148,7 @@ ipifcbind(Conv *c, char **argv, int argc) /* * detach a device from an interface, close the interface + * called with ifc->conv closed */ static char* ipifcunbind(Ipifc *ifc) @@ -166,11 +164,8 @@ ipifcunbind(Ipifc *ifc) wlock(ifc); /* dissociate routes */ - if(ifc->m != nil && ifc->m->unbindonclose == 0){ - qlock(ifc->conv); + if(ifc->m != nil && ifc->m->unbindonclose == 0) ifc->conv->inuse--; - qunlock(ifc->conv); - } ifc->ifcid++; /* disassociate device */ @@ -309,7 +304,6 @@ ipifcclose(Conv *c) m = ifc->m; if(m != nil && m->unbindonclose) ipifcunbind(ifc); - qunlock(c); } /* diff --git a/ip/ipmux.c b/ip/ipmux.c index ba5e8b3dbc32566b3014ff5794b9af35dca0a329..cf91da6ccb3b41fd7ef5090d2027f61571545703 100644 --- a/ip/ipmux.c +++ b/ip/ipmux.c @@ -619,8 +619,6 @@ ipmuxclose(Conv *c) wunlock(f); ipmuxtreefree(r->chain); r->chain = nil; - - qunlock(c); } /* diff --git a/ip/rudp.c b/ip/rudp.c index 3dda3da3cdefccee7cf7975aeae3bf43f0d03880..a704c9709217fd23ca5b1109b59a8426974301f6 100644 --- a/ip/rudp.c +++ b/ip/rudp.c @@ -296,7 +296,6 @@ rudpclose(Conv *c) ucb->r = 0; qunlock(ucb); - qunlock(c); } /* diff --git a/ip/tcp.c b/ip/tcp.c index ab0fa509664819f03f584eb7b2187dace03cc397..62dcf35cd1c213e3319b3f2aa98ea8ac01d410ad 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -402,7 +402,6 @@ tcpclose(Conv *c) tcpoutput(c); break; } - qunlock(c); } void @@ -412,6 +411,11 @@ tcpkick(Conv *s, int len) tcb = (Tcpctl*)s->ptcl; + if(waserror()){ + qunlock(s); + nexterror(); + } + qlock(s); switch(tcb->state) { case Listen: @@ -426,22 +430,17 @@ tcpkick(Conv *s, int len) /* * Push data */ - if(waserror()){ - qunlock(s); - nexterror(); - } - qlock(s); tcb->sndcnt += len; tcprcvwin(s); tcpoutput(s); - qunlock(s); - poperror(); break; default: - qlock(s); localclose(s, "Hangup"); - qunlock(s); + break; } + + qunlock(s); + poperror(); } void @@ -682,6 +681,9 @@ inittcpctl(Conv *s) tcb->mss = tcb->cwind = tcpmtu(s); } +/* + * called with s qlocked + */ void tcpstart(Conv *s, int mode, ushort window) { @@ -703,13 +705,7 @@ tcpstart(Conv *s, int mode, ushort window) tcb = (Tcpctl*)s->ptcl; - qlock(s); /* Send SYN, go into SYN_SENT state */ - if(waserror()){ - qunlock(s); - nexterror(); - } - inittcpctl(s); tcb->window = window; tcb->rcv.wnd = window; @@ -729,8 +725,6 @@ tcpstart(Conv *s, int mode, ushort window) tcpoutput(s); break; } - qunlock(s); - poperror(); } static char* diff --git a/ip/udp.c b/ip/udp.c index 209f4fbaaf0621da4f1885523bd87bf8f80960fd..003fc1a76006f4e80b56580d6451eb10422bb5df 100644 --- a/ip/udp.c +++ b/ip/udp.c @@ -140,8 +140,6 @@ udpclose(Conv *c) ucb = (Udpcb*)c->ptcl; ucb->headers = 0; - - qunlock(c); } void @@ -404,22 +402,22 @@ found: } -/* close any incoming calls waiting on this conversation */ +/* + * close any incoming calls waiting on this conversation + * called with c locked + */ void udpcloseincalls(Conv *c) { Conv *nc; - qlock(c); - for(nc = c->incall; nc; nc = c->incall){ c->incall = nc->next; closeconv(nc); } - - qunlock(c); } +/* called with c locked */ char* udpctl(Conv *c, char **f, int n) { diff --git a/port/error.h b/port/error.h index 4cf4554a762855eb64d483f85da1a58bcc3e6aa9..9c90b6afe865b306700c377cc527ce5c1eb9bd33 100644 --- a/port/error.h +++ b/port/error.h @@ -33,6 +33,7 @@ extern char Eisstream[]; /* seek on a stream */ extern char Ebadexec[]; /* exec header invalid */ extern char Etimedout[]; /* connection timed out */ extern char Econrefused[]; /* connection refused */ +extern char Econinuse[]; /* connection in use */ extern char Eintr[]; /* interrupted */ extern char Enomem[]; /* kernel allocate failed */ extern char Enoswap[]; /* swap space full */