M port/devssl.c => port/devssl.c +6 -6
@@ 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();
M port/portdat.h => port/portdat.h +1 -0
@@ 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
M port/portfns.h => port/portfns.h +5 -1
@@ 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);
M port/qio.c => port/qio.c +36 -2
@@ 233,6 233,23 @@ pullupblock(Block *bp, int n)
}
/*
+ * 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
*/
Block *
@@ 812,9 829,26 @@ qwait(Queue *q)
}
/*
+ * 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;