From 9d8e6c11ac0d589a60d4ff42badd6ba38e1e99f1 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 6 Apr 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-04-06 --- gnot/dat.h | 4 ++-- gnot/stream.c | 8 +++----- gnot/sturp.c | 33 ++++++++++++++++++++++----------- port/stream.c | 7 ++----- port/sturp.c | 24 ++++++++++++------------ power/dat.h | 6 +++--- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index 43a239bc6c0ecf97b5efc3c04d2e8c8175f17583..250e95f5fdb8f5bbb53d157de573f5340522b8f2 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -383,6 +383,7 @@ struct Blist { Block *first; /* first data block */ Block *last; /* last data block */ long len; /* length of list in bytes */ + int nb; /* number of blocks in list */ }; /* @@ -390,7 +391,6 @@ struct Blist { */ struct Queue { Blist; - int nb; /* number of blocks in queue */ int flag; Qinfo *info; /* line discipline definition */ Queue *other; /* opposite direction, same line discipline */ @@ -428,7 +428,7 @@ struct Stream { #define PUTNEXT(q,b) (*(q)->next->put)((q)->next, b) #define BLEN(b) ((b)->wptr - (b)->rptr) #define QFULL(q) ((q)->flag & QHIWAT) -#define FLOWCTL(q) { if(QFULL(q)) flowctl(q); } +#define FLOWCTL(q) { if(QFULL(q->next)) flowctl(q); } /* * stream file qid's & high water mark diff --git a/gnot/stream.c b/gnot/stream.c index f9856ed92df0af6343880fc70f79e0e2453062df..944348610568e9862b6a964911d8c7db8214fe21 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -372,6 +372,7 @@ putbq(Blist *q, Block *bp) q->last = bp; q->first = bp; q->len += BLEN(bp); + q->nb++; unlock(q); } @@ -391,7 +392,7 @@ getq(Queue *q) q->last = 0; q->len -= BLEN(bp); q->nb--; - if((q->flag&QHIWAT) && q->len < Streamhi/2 && q->nb < Streambhi){ + if((q->flag&QHIWAT) && q->lennbother->next->other->r); q->flag &= ~QHIWAT; } @@ -941,10 +942,7 @@ streamctlwrite(Stream *s, void *a, long n) static int notfull(void *arg) { - Queue *q; - - q = (Queue *)arg; - return !QFULL(q->next); + return !QFULL((Queue *)arg); } void flowctl(Queue *q) diff --git a/gnot/sturp.c b/gnot/sturp.c index 6da19f7356502d78297e59d451fb64f82854cb65..a603045da1475471dcdb23064756469d7eda0d95 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -207,6 +207,9 @@ urpclose(Queue *q) * kill off the kernel process */ wakeup(&up->rq->r); + + if(up->kstarted == 0) + up->state = 0; } /* @@ -572,18 +575,20 @@ output(Urp *up) * fill the transmit buffers */ q = up->wq; - for(bp = getq(q); bp && up->xb[up->nxb]==0; up->nxb = NEXT(up->nxb)){ - if(BLEN(bp) > up->maxblock){ - nbp = up->xb[up->nxb] = allocb(0); - nbp->rptr = bp->rptr; - nbp->wptr = bp->rptr = bp->rptr + up->maxblock; - } else { - up->xb[up->nxb] = bp; - bp = getq(q); + if(up->xb[up->nxb]==0) { + for(bp=getq(q); bp && up->xb[up->nxb]==0; up->nxb=NEXT(up->nxb)){ + if(BLEN(bp) > up->maxblock){ + nbp = up->xb[up->nxb] = allocb(0); + nbp->rptr = bp->rptr; + nbp->wptr = bp->rptr = bp->rptr + up->maxblock; + } else { + up->xb[up->nxb] = bp; + bp = getq(q); + } } + if(bp) + putbq(q, bp); } - if(bp) - putbq(q, bp); /* print("output w(%d) up->xb[%d](%ux) up->nxb(%d) up->state(%ux)\n", WINDOW(up), up->next, up->xb[up->next], up->nxb, up->state); /**/ @@ -868,6 +873,12 @@ urpkproc(void *arg) up = (Urp *)arg; + if(waserror()){ + up->state = 0; + up->kstarted = 0; + wakeup(&up->r); + return; + } for(;;){ if(up->state & (HUNGUP|CLOSING)){ if(isflushed(up)) @@ -879,6 +890,6 @@ urpkproc(void *arg) output(up); tsleep(&up->rq->r, todo, up, MSrexmit/2); } - up->kstarted = 0; up->state = 0; + up->kstarted = 0; } diff --git a/port/stream.c b/port/stream.c index b26800edafb68cc7f414a29e3fee99d9556cba8b..944348610568e9862b6a964911d8c7db8214fe21 100644 --- a/port/stream.c +++ b/port/stream.c @@ -392,7 +392,7 @@ getq(Queue *q) q->last = 0; q->len -= BLEN(bp); q->nb--; - if((q->flag&QHIWAT) && q->len < Streamhi/2 && q->nb < Streambhi){ + if((q->flag&QHIWAT) && q->lennbother->next->other->r); q->flag &= ~QHIWAT; } @@ -942,10 +942,7 @@ streamctlwrite(Stream *s, void *a, long n) static int notfull(void *arg) { - Queue *q; - - q = (Queue *)arg; - return !QFULL(q->next); + return !QFULL((Queue *)arg); } void flowctl(Queue *q) diff --git a/port/sturp.c b/port/sturp.c index 62c3fb61b52f3b4c1241cfa342cf9f90bddff77c..a603045da1475471dcdb23064756469d7eda0d95 100644 --- a/port/sturp.c +++ b/port/sturp.c @@ -575,20 +575,20 @@ output(Urp *up) * fill the transmit buffers */ q = up->wq; - for(bp = getq(q); q->first && up->xb[up->nxb]==0; up->nxb = NEXT(up->nxb)){ - if(bp == 0) - bp = getq(q); - if(BLEN(bp) > up->maxblock){ - nbp = up->xb[up->nxb] = allocb(0); - nbp->rptr = bp->rptr; - nbp->wptr = bp->rptr = bp->rptr + up->maxblock; - } else { - up->xb[up->nxb] = bp; - bp = 0; + if(up->xb[up->nxb]==0) { + for(bp=getq(q); bp && up->xb[up->nxb]==0; up->nxb=NEXT(up->nxb)){ + if(BLEN(bp) > up->maxblock){ + nbp = up->xb[up->nxb] = allocb(0); + nbp->rptr = bp->rptr; + nbp->wptr = bp->rptr = bp->rptr + up->maxblock; + } else { + up->xb[up->nxb] = bp; + bp = getq(q); + } } + if(bp) + putbq(q, bp); } - if(bp) - putbq(q, bp); /* print("output w(%d) up->xb[%d](%ux) up->nxb(%d) up->state(%ux)\n", WINDOW(up), up->next, up->xb[up->next], up->nxb, up->state); /**/ diff --git a/power/dat.h b/power/dat.h index 22ae85938663a6daeb187a194f1a27f982a93566..85ec85b8b7bbecc1a63ed498bbdd723dcd2ac784 100644 --- a/power/dat.h +++ b/power/dat.h @@ -400,6 +400,7 @@ struct Blist { Block *first; /* first data block */ Block *last; /* last data block */ long len; /* length of list in bytes */ + int nb; /* number of blocks in list */ }; /* @@ -407,7 +408,6 @@ struct Blist { */ struct Queue { Blist; - int nb; /* number of blocks in queue */ int flag; Qinfo *info; /* line discipline definition */ Queue *other; /* opposite direction, same line discipline */ @@ -445,7 +445,7 @@ struct Stream { #define PUTNEXT(q,b) (*(q)->next->put)((q)->next, b) #define BLEN(b) ((b)->wptr - (b)->rptr) #define QFULL(q) ((q)->flag & QHIWAT) -#define FLOWCTL(q) { if(QFULL(q)) flowctl(q); } +#define FLOWCTL(q) { if(QFULL(q->next)) flowctl(q); } /* * stream file qid's & high water mark @@ -455,7 +455,7 @@ enum { Sdataqid = Shighqid, Sctlqid = Sdataqid-1, Slowqid = Sctlqid, - Streamhi= (9*1024), /* byte count high water mark */ + Streamhi= (17*1024), /* byte count high water mark */ Streambhi= 16, /* block count high water mark */ };