|
|
1.1 ! root 1: /* finput.c - finput, sendack, sendnack, sendsack */ ! 2: ! 3: #include <conf.h> ! 4: #include <kernel.h> ! 5: #include <frame.h> ! 6: ! 7: /*------------------------------------------------------------------------ ! 8: * finput -- read frames and enqueue for local machine or forwarding ! 9: *------------------------------------------------------------------------ ! 10: */ ! 11: PROCESS finput(netid) ! 12: int netid; ! 13: { ! 14: int len; /* length of actual data */ ! 15: int to, from; /* "to" and "from" addresses */ ! 16: struct fglob *fgptr; ! 17: struct frame *fptr, *fptr2; ! 18: char *t, *f; /* used to copy broadcast frames*/ ! 19: ! 20: fgptr = &fdata[netid]; ! 21: fptr = getbuf(frbpool); ! 22: for (fgptr->fiseq = fgptr->fifails = 0 ; TRUE ; ) { ! 23: len = read(fgptr->findev, fptr, FRMAXLEN); ! 24: if (len < FRMINLEN || len != getflen(fptr)) ! 25: sendnack(fgptr); ! 26: else if ( (int)fptr->frseq != fgptr->fiseq) ! 27: sendsack(fgptr); ! 28: else { ! 29: to = getfto(fptr->fraddr); ! 30: from = getfrom(fptr->fraddr); ! 31: if (to == FRBCAST) { /* broadcast */ ! 32: if (from == fgptr->fmachid) { ! 33: psend(fgptr->fiport, fptr); ! 34: fptr = getbuf(frbpool); ! 35: } else { ! 36: fptr2 = getbuf(frbpool); ! 37: for (f=fptr,t=fptr2; len-->0; ) ! 38: *t++ = *f++; ! 39: psend(fgptr->fiport, fptr); ! 40: psend(fgptr->ffport, fptr2); ! 41: signal(fgptr->fosem); ! 42: fptr = getbuf(frbpool); ! 43: } ! 44: } else if (to == fgptr->fmachid) { ! 45: psend(fgptr->fiport, fptr); ! 46: fptr = getbuf(frbpool); ! 47: } else if (from == fgptr->fmachid) { ! 48: printf("Can't deliver to %d\n", to); ! 49: } else { ! 50: psend(fgptr->ffport, fptr); ! 51: signal(fgptr->fosem); /* bug fix to text */ ! 52: fptr = getbuf(frbpool); ! 53: } ! 54: sendack(fgptr); ! 55: } ! 56: } ! 57: } ! 58: ! 59: /*------------------------------------------------------------------------ ! 60: * sendack -- send a positive acknowledgement with sequence number ! 61: *------------------------------------------------------------------------ ! 62: */ ! 63: LOCAL sendack(fgptr) ! 64: struct fglob *fgptr; ! 65: { ! 66: fgptr->fifails = 0; ! 67: if (++fgptr->fiseq > FRMAXSEQ) ! 68: fgptr->fiseq = 0; ! 69: putc(fgptr->findev, FRACK | fgptr->fiseq); ! 70: } ! 71: ! 72: /*------------------------------------------------------------------------ ! 73: * sendnack -- send a negative acknowledgement with sequence number ! 74: *------------------------------------------------------------------------ ! 75: */ ! 76: LOCAL sendnack(fgptr) ! 77: struct fglob *fgptr; ! 78: { ! 79: putc(fgptr->findev, FRNACK | fgptr->fiseq); ! 80: } ! 81: ! 82: /*------------------------------------------------------------------------ ! 83: * sendsack -- send a negative acknowledgement and restart sequence ! 84: *------------------------------------------------------------------------ ! 85: */ ! 86: LOCAL sendsack(fgptr) ! 87: struct fglob *fgptr; ! 88: { ! 89: if (++fgptr->fifails >= FRFAIL) { ! 90: fgptr->fiseq = 0; ! 91: fgptr->fifails = 0; ! 92: putc(fgptr->findev, FRSACK); ! 93: } else ! 94: putc(fgptr->findev, FRNACK); ! 95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.