From 4198aa10805da47875c0f9ae037e9fe9bc72d2ea Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 2 Jun 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-06-02 --- port/devssl.c | 12 ++++++------ port/portdat.h | 1 + port/portfns.h | 6 +++++- port/qio.c | 38 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/port/devssl.c b/port/devssl.c index b4b03692a9d9831dc9f73b2f2c25febf3a0dcbcb..598355ea0f7504dd79f850d5ada21cafd3421fd3 100644 --- a/port/devssl.c +++ b/port/devssl.c @@ -484,7 +484,7 @@ regurgitate(Dstate *s, uchar *p, int n) * dump the remainder */ static Block* -qremove(Block **l, int n, int discard) +qtake(Block **l, int n, int discard) { Block *nb, *b, *first; int i; @@ -516,12 +516,12 @@ qremove(Block **l, int n, int discard) } b->next = 0; if(BLEN(b) < 0) - panic("qremove"); + panic("qtake"); return first; } else n -= i; if(BLEN(b) < 0) - panic("qremove"); + panic("qtake"); } *l = 0; return first; @@ -586,7 +586,7 @@ sslbread(Chan *c, long n, ulong) */ /* grab the next message and decode/decrypt it */ - b = qremove(&s.s->unprocessed, len, 0); + b = qtake(&s.s->unprocessed, len, 0); if(waserror()){ qunlock(&s.s->in.ctlq); @@ -619,7 +619,7 @@ sslbread(Chan *c, long n, ulong) /* remove pad */ if(pad) - s.s->processed = qremove(&b, len - pad, 1); + s.s->processed = qtake(&b, len - pad, 1); else s.s->processed = b; b = nil; @@ -630,7 +630,7 @@ sslbread(Chan *c, long n, ulong) } /* return at most what was asked for */ - b = qremove(&s.s->processed, n, 0); + b = qtake(&s.s->processed, n, 0); qunlock(&s.s->in.q); poperror(); diff --git a/port/portdat.h b/port/portdat.h index a7301a636ee72e4cb568764da7200b484ebc977f..07b3c4fe45634b7a3237847e1c50083352c060ac 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -262,6 +262,7 @@ struct Mnt ulong id; /* Multiplexer id for channel check */ Mnt *list; /* Free list */ int flags; /* cache */ + Queue *q; /* input queue */ }; enum diff --git a/port/portfns.h b/port/portfns.h index 4dea14b2a6b97adea296f6db232c14650172111b..3849e08d6907e2d3023264a0d6b2c1e470f2fc3d 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -209,6 +209,7 @@ Pte* ptealloc(void); Pte* ptecpy(Pte*); int pullblock(Block**, int); Block* pullupblock(Block*, int); +Block* pullupqueue(Queue*, int); void putimage(Image*); void putmhead(Mhead*); void putmmu(ulong, ulong, Page*); @@ -219,6 +220,7 @@ void putstr(char*); void putstrn(char*, int); void putswap(Page*); ulong pwait(Waitmsg*); +void qadd(Queue*, Block*); Block* qbread(Queue*, int); long qbwrite(Queue*, Block*); int qcanread(Queue*); @@ -240,12 +242,14 @@ Queue* qopen(int, int, void (*)(void*), void*); int qpass(Queue*, Block*); int qpassnolim(Queue*, Block*); int qproduce(Queue*, void*, int); +void qputback(Queue*, Block*); long qread(Queue*, void*, int); +Block* qremove(Queue*); void qreopen(Queue*); +void qsetlimit(Queue*, int); void qunlock(QLock*); int qwindow(Queue*); int qwrite(Queue*, void*, int); -void qsetlimit(Queue*, int); void qnoblock(Queue*, int); int rand(void); void randominit(void); diff --git a/port/qio.c b/port/qio.c index 3ac46de4e53a04ba226f3072234ce5933254e0a3..224f11e146888015d2a10c58e7c988c7174c8efc 100644 --- a/port/qio.c +++ b/port/qio.c @@ -232,6 +232,23 @@ pullupblock(Block *bp, int n) return 0; } +/* + * make sure the first block has at least n bytes + */ +Block* +pullupqueue(Queue *q, int n) +{ + Block *b; + + if(BLEN(q->bfirst) >= n) + return q->bfirst; + q->bfirst = pullupblock(q->bfirst, n); + for(b = q->bfirst; b != nil && b->next != nil; b = b->next) + ; + q->blast = b; + return q->bfirst; +} + /* * trim to len bytes starting at offset */ @@ -811,10 +828,27 @@ qwait(Queue *q) return 1; } +/* + * add a block to a queue + */ +void +qadd(Queue *q, Block *b) +{ + /* queue the block */ + if(q->bfirst) + q->blast->next = b; + else + q->bfirst = b; + q->blast = b; + b->next = 0; + q->len += BALLOC(b); + q->dlen += BLEN(b); +} + /* * called with q ilocked */ -static Block* +Block* qremove(Queue *q) { Block *b; @@ -834,7 +868,7 @@ qremove(Queue *q) * put a block back to the front of the queue * called with q ilocked */ -static void +void qputback(Queue *q, Block *b) { b->next = q->bfirst;