Annotation of researchv9/sys/net/netutil.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *            N E T  U T I L
        !             3:  *
        !             4:  * Utility routines used by various network kernel code.
        !             5:  *
        !             6:  *
        !             7:  * Written by Kurt Gollhardt  (Nirvonics, Inc.)
        !             8:  * Last update Fri Apr  5 16:36:40 1985
        !             9:  *
        !            10:  */
        !            11: 
        !            12: #include "../h/param.h"
        !            13: #include "../h/stream.h"
        !            14: 
        !            15: #define BLEN(bp)    ((bp)->wptr - (bp)->rptr)
        !            16: #define BSZ(bp)            ((bp)->lim - (bp)->base)
        !            17: #undef MIN
        !            18: #define MIN(a,b)    ((a) > (b) ? (b) : (a))
        !            19: 
        !            20: extern int bsize[];
        !            21: 
        !            22: 
        !            23: struct block *block_pullup(q, len)
        !            24:      register struct queue *q;
        !            25: {
        !            26:      register struct block *bp, *m;
        !            27:      int count, ps = spl6();
        !            28: 
        !            29:      if ((bp = q->first) == 0)
        !            30:           goto bad;
        !            31:      if (BLEN(bp) >= len) {
        !            32:           splx(ps);
        !            33:           return bp;
        !            34:      }
        !            35: 
        !            36:      m = allocb(len);
        !            37:      if (m == 0 || BSZ(m) < len)
        !            38:           goto bad;
        !            39:      m->next = bp;
        !            40:      q->first = m;
        !            41:      q->count += bsize[m->class];
        !            42: 
        !            43:      while (bp && bp->type == M_DATA) {
        !            44:          count = BSZ(m) - BLEN(m);
        !            45:           count = MIN(count, len);
        !            46:          count = MIN(count, BLEN(bp));
        !            47:           bcopy(bp->rptr, m->wptr, (unsigned)count);
        !            48:           len -= count;
        !            49:           m->wptr += count;
        !            50:           bp->rptr += count;
        !            51:           if (BLEN(bp) > 0)
        !            52:                break;
        !            53:          if (q->last == bp)
        !            54:               q->last = m;
        !            55:          q->count -= bsize[bp->class];
        !            56:           m->next = bp->next;
        !            57:           freeb(bp);
        !            58:          bp = m->next;
        !            59:      }
        !            60: 
        !            61:      if (len == 0) {
        !            62:           splx(ps);
        !            63:           return m;
        !            64:      }
        !            65: bad:
        !            66:      splx(ps);
        !            67:      printf("block_pullup bad\n");
        !            68:      return 0;
        !            69: }
        !            70: 
        !            71: 
        !            72:      /* Removes blocks through first delim; returns true if delim found */
        !            73: flush_packet(q)
        !            74:      register struct queue    *q;
        !            75: {
        !            76:      register struct block    *bp;
        !            77:      register int   isdelim;
        !            78: 
        !            79:      while (bp = getq(q)) {
        !            80:           isdelim = (bp->type == M_DELIM);
        !            81:          freeb(bp);
        !            82:          if (isdelim)
        !            83:               return 1;
        !            84:      }
        !            85:      return 0;
        !            86: }

unix.superglobalmegacorp.com

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