Annotation of researchv8dc/sys/dev/bufld.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * buffering line discipline.
        !             3:  *  transparent, but saves up characters for a while.
        !             4:  */
        !             5: 
        !             6: #include "bf.h"
        !             7: #if NBF
        !             8: #include "../h/param.h"
        !             9: #include "../h/systm.h"
        !            10: #include "../h/stream.h"
        !            11: #include "../h/ioctl.h"
        !            12: #include "../h/map.h"
        !            13: #include "../h/buf.h"
        !            14: #include "../h/ubavar.h"
        !            15: #include "../h/conf.h"
        !            16: 
        !            17: struct bufld {
        !            18:        struct  queue *queue;
        !            19:        u_char  rnchar;
        !            20:        u_char  btime;
        !            21:        u_char  nchar;
        !            22:        u_char  nclick;
        !            23:        u_char  index;
        !            24: } bufld[NBF];
        !            25: 
        !            26: int    buftimo();
        !            27: int    bufopen(), bufput(), bufsrv(), bufclose();
        !            28: long   bufldact;
        !            29: 
        !            30: static struct qinit bufrinit = { bufput, bufsrv, bufopen, bufclose, 1024, 512 };
        !            31: static struct qinit bufwinit = { bufput, bufsrv, bufopen, bufclose, 128, 64 };
        !            32: struct streamtab bufinfo = { &bufrinit, &bufwinit };
        !            33: 
        !            34: bufopen(q, dev)
        !            35: register struct queue *q;
        !            36: {
        !            37:        register i;
        !            38:        register struct bufld *fp;
        !            39: 
        !            40:        if (q->ptr)
        !            41:                return(1);
        !            42:        for (i=0; bufld[i].queue!=0 && i<NBF; i+= 2)
        !            43:                ;
        !            44:        if (i >= NBF)
        !            45:                return(0);
        !            46:        fp = &bufld[i];
        !            47:        fp->queue = q;
        !            48:        (fp+1)->queue = WR(q);
        !            49:        fp->index = i;
        !            50:        (fp+1)->index = i+1;
        !            51:        fp->nclick = 3;
        !            52:        (fp+1)->nclick = 3;
        !            53:        fp->nchar = 16;
        !            54:        (fp+1)->nchar = 16;
        !            55:        fp->rnchar = 0;
        !            56:        (fp+1)->rnchar = 0;
        !            57:        fp->btime = 0;
        !            58:        (fp+1)->btime = 0;
        !            59:        q->flag |= q->next->flag & QDELIM;
        !            60:        WR(q)->flag |= WR(q)->next->flag & QDELIM;
        !            61:        q->ptr = (caddr_t)fp;
        !            62:        WR(q)->ptr = (caddr_t)(fp+1);
        !            63:        q->flag |= QNOENB;
        !            64:        WR(q)->flag |= QNOENB;
        !            65:        return(1);
        !            66: }
        !            67: 
        !            68: bufclose(q)
        !            69: register struct queue *q;
        !            70: {
        !            71: 
        !            72:        bufunload(q);
        !            73:        bufunload(WR(q));
        !            74:        ((struct bufld *)q->ptr)->btime = 0;
        !            75:        ((struct bufld *)WR(q)->ptr)->btime = 0;
        !            76:        ((struct bufld *)q->ptr)->queue = 0;
        !            77:        ((struct bufld *)WR(q)->ptr)->queue = 0;
        !            78: }
        !            79: 
        !            80: bufput(q, bp)
        !            81: register struct queue *q;
        !            82: register struct block *bp;
        !            83: {
        !            84:        register struct bufld *fp = (struct bufld *)q->ptr;
        !            85:        register s = spl6();
        !            86:        register n, t;
        !            87: 
        !            88:        t = bp->type;
        !            89:        n = bp->wptr - bp->rptr;
        !            90:        putq(q, bp);
        !            91:        fp->rnchar += n;
        !            92:        if ((t!=M_DATA && t!=M_DELIM) || fp->rnchar >= fp->nchar)
        !            93:                bufunload(q);
        !            94:        if (q->first) {
        !            95:                /* n/2 ~ about 1200 cps */
        !            96:                fp->btime = fp->nclick + n/2;
        !            97:                if (bufldact == 0)
        !            98:                        timeout(buftimo, (caddr_t)0, 1);
        !            99:                bufldact |= 1 << fp->index;
        !           100:        } else  {
        !           101:                fp->rnchar = 0;
        !           102:                fp->btime = 0;
        !           103:        }
        !           104:        splx(s);
        !           105: }
        !           106: 
        !           107: bufsrv(q)
        !           108: register struct queue *q;
        !           109: {
        !           110:        register struct bufld *fp = (struct bufld *)q->ptr;
        !           111: 
        !           112:        if (q->first && fp->btime == 0)
        !           113:                bufunload(q);
        !           114: }
        !           115: 
        !           116: bufunload(q)
        !           117: register struct queue *q;
        !           118: {
        !           119:        register struct block *bp;
        !           120:        register struct bufld *fp = (struct bufld *)q->ptr;
        !           121: 
        !           122:        while ((q->next->flag&QFULL)==0 && (bp = getq(q))) {
        !           123:                fp->rnchar -= bp->wptr - bp->rptr;
        !           124:                (*q->next->qinfo->putp)(q->next, bp);
        !           125:        }
        !           126: }
        !           127: 
        !           128: buftimo()
        !           129: {
        !           130:        register long bact;
        !           131:        register struct bufld *fp;
        !           132:        register ish;
        !           133: 
        !           134:        bact = bufldact;
        !           135:        for (fp = bufld, ish = 1; bact!=0; fp++, ish <<= 1) {
        !           136:                if (bact & ish) {
        !           137:                        bact &= ~ish;
        !           138:                        if (fp->btime) {
        !           139:                                fp->btime--;
        !           140:                                if (fp->btime == 0 && fp->queue
        !           141:                                 && fp->queue->first) {
        !           142:                                        qenable(fp->queue);
        !           143:                                        bufldact &= ~ish;
        !           144:                                }
        !           145:                        }
        !           146:                }
        !           147:        }
        !           148:        if (bufldact)
        !           149:                timeout(buftimo, (caddr_t)0, 1);
        !           150: }
        !           151: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.