From c126beffa146b9e3f420b04ec3ea0edeacf28321 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 27 Nov 1998 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1998-11-27 --- ip/devip.c | 5 +++++ ip/rudp.c | 4 ++-- ip/tcp.c | 2 ++ port/portfns.h | 1 + port/qio.c | 15 +++++++++++++-- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ip/devip.c b/ip/devip.c index 373246971d2cbcd4de80f7e8afcdb0b84f3caee5..a3177f71cebcfdc6c4609f684a1918a12fd52ff4 100644 --- a/ip/devip.c +++ b/ip/devip.c @@ -409,12 +409,17 @@ ipopen(Chan* c, int omode) nc = nil; while(nc == nil) { + /* give up if we got a hangup */ + if(qisclosed(cv->rq)) + error("listen hungup"); + qlock(&cv->listenq); if(waserror()) { qunlock(&cv->listenq); nexterror(); } + /* wait for a connect */ sleep(&cv->listenr, incoming, cv); lock(cv); diff --git a/ip/rudp.c b/ip/rudp.c index bdcdd1f874f923a84147521baf59239651f0a0e2..6bed2d98028e330c6709589abfd0a32b31cdbc0d 100644 --- a/ip/rudp.c +++ b/ip/rudp.c @@ -774,7 +774,7 @@ relstate(Rudpcb *ucb, uchar *addr, ushort port, char *from) /* no state for this addr/port, create some */ if(r == nil){ - if(generation == 0) + while(generation == 0) generation = rand(); DPRINT("from %s new state %lud for %I!%ud\n", from, generation, addr, port); @@ -834,7 +834,7 @@ reliput(Conv *c, Block *bp, uchar *addr, ushort port) /* make sure we're not talking to a new remote side */ if(r->rcvgen != sgen){ - if(seq != 1) + if(seq != 0 && seq != 1) return -1; /* new connection */ diff --git a/ip/tcp.c b/ip/tcp.c index 09a25012077aeb7e7029cc0c34bba64a1bc2183b..fceae8d99755c52083c1f9a262daf26eff783a53 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -567,6 +567,8 @@ localclose(Conv *s, char *reason) /* called with tcb locked */ if(tcb->state == Syn_sent) Fsconnected(s, reason); + if(s->state == Announced) + wakeup(&s->listenr); qhangup(s->rq, reason); qhangup(s->wq, reason); diff --git a/port/portfns.h b/port/portfns.h index 3f86bbd98219a03c923bd3d52e5440b0c1b39e57..ecaaf088f3234f9a177856f490590ee270c51b34 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -224,6 +224,7 @@ void qflush(Queue*); int qfull(Queue*); Block* qget(Queue*); void qhangup(Queue*, char*); +int qisclosed(Queue*); void qinit(void); int qiwrite(Queue*, void*, int); int qlen(Queue*); diff --git a/port/qio.c b/port/qio.c index c31a049d378b1063d01675629cc4170a282afeb6..e954ee1970ade77fb185a0e581796f8ad5728409 100644 --- a/port/qio.c +++ b/port/qio.c @@ -147,14 +147,16 @@ iallocb(int size) int n; if(ialloc.bytes > conf.ialloc){ - iprint("iallocb: limited %d/%d\n", ialloc.bytes, conf.ialloc); + print("iallocb: limited %d/%d\n", + ialloc.bytes, conf.ialloc); return 0; } n = sizeof(Block) + size + (BY2V-1); b = mallocz(n+Hdrspc, 0); if(b == nil){ - iprint("iallocb: no memory %d/%d\n", ialloc.bytes, conf.ialloc); + print("iallocb: no memory %d/%d\n", + ialloc.bytes, conf.ialloc); return nil; } memset(b, 0, sizeof(Block)); @@ -1229,6 +1231,15 @@ qhangup(Queue *q, char *msg) wakeup(&q->wr); } +/* + * return non-zero if the q is hungup + */ +int +qisclosed(Queue *q) +{ + return q->state & Qclosed; +} + /* * mark a queue as no longer hung up */