home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / TCPTIMER.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  2KB  |  69 lines

  1. /* TCP timeout routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4. #include "global.h"
  5. #include "mbuf.h"
  6. #include "timer.h"
  7. #include "netuser.h"
  8. #include "internet.h"
  9. #include "iface.h"
  10. #include "tcp.h"
  11.   
  12. int tcptimertype;       /* default backoff to binary exponential */
  13. int Tcp_blimit = 31;
  14.   
  15. /* Timer timeout */
  16. void
  17. tcp_timeout(p)
  18. void *p;
  19. {
  20.     struct tcb *tcb;
  21.   
  22.     if(p == NULL)
  23.         return;
  24.     tcb = (struct tcb *)p;
  25.   
  26.     /* Make sure the timer has stopped (we might have been kicked) */
  27.     stop_timer(&tcb->timer);
  28.   
  29.     switch(tcb->state){
  30.         case TCP_TIME_WAIT: /* 2MSL timer has expired */
  31.             close_self(tcb,NORMAL);
  32.             break;
  33.         default:        /* Retransmission timer has expired */
  34.             tcb->flags.retran = 1;  /* Indicate > 1  transmission */
  35.             if( !tcb->parms->retries || tcb->backoff < tcb->parms->retries) {
  36.                 tcb->backoff++;
  37.                 tcb->snd.ptr = tcb->snd.una;
  38.             /* Reduce slowstart threshold to half current window */
  39.                 tcb->ssthresh = tcb->cwind / 2;
  40.                 tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  41.             /* Shrink congestion window to 1 packet */
  42.                 tcb->cwind = tcb->mss;
  43.                 tcp_output(tcb);
  44.             } else reset_tcp(tcb);
  45.     }
  46. }
  47.   
  48. /* Backoff function - the subject of much research */
  49. int32
  50. backoff(struct tcb *tcb)
  51. {
  52.     int n = tcb->backoff;
  53.     struct iftcp *parms = tcb->parms;
  54.   
  55.     if(tcb->parms->timertype) {  /* Linear */
  56.         if(n >= parms->blimit)     /* At backoff limit -- N1BEE */
  57.             n = parms->blimit;
  58.         else
  59.             ++n;
  60.         return (int32) n;     /* Linear backoff for sensible values! */
  61.     } else {        /* Binary exponential */
  62.         if(n > min(31,parms->blimit))
  63.             n = min(31,parms->blimit);
  64.                 /* Prevent truncation to zero */
  65.         return 1L << n; /* Binary exponential back off */
  66.     }
  67. }
  68.   
  69.