home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / internet / netlite2 / NET / c / TCPTIMER < prev    next >
Encoding:
Text File  |  1992-02-13  |  1.5 KB  |  53 lines

  1. /* TCP timeout routines */
  2. #include <stdio.h>
  3. #include "global.h"
  4. #include "mbuf.h"
  5. #include "timer.h"
  6. #include "netuser.h"
  7. #include "internet.h"
  8. #include "tcp.h"
  9.  
  10. /* Timer timeout */
  11. void tcp_timeout(char *arg)
  12. {
  13.         register struct tcb *tcb;
  14.  
  15.         tcb = (struct tcb *)arg;
  16.  
  17.         if(tcb == NULLTCB)
  18.                 return;
  19.  
  20.         /* Make sure the timer has stopped (we might have been kicked) */
  21.         stop_timer(&tcb->timer);
  22.  
  23.         switch(tcb->state){
  24.         case TIME_WAIT:         /* 2MSL timer has expired */
  25.                 close_self(tcb,NORMAL);
  26.                 break;
  27.         default:                /* Retransmission timer has expired */
  28.                 tcb->flags |= RETRAN;   /* Indicate > 1  transmission */
  29.                 tcb->backoff++;
  30.                 tcb->snd.ptr = tcb->snd.una;
  31.                 /* Reduce slowstart threshold to half current window */
  32.                 tcb->ssthresh = tcb->cwind / 2;
  33.                 tcb->ssthresh = max(tcb->ssthresh,tcb->mss);
  34.                 /* Shrink congestion window to 1 packet */
  35.                 tcb->cwind = tcb->mss;
  36.                 tcp_output(tcb);
  37.         }
  38. }
  39. /* Backoff function - the subject of much research */
  40. int backoff(int n)
  41. {
  42.         /* Use binary exponential up to retry #4, and quadratic after that
  43.          * This yields the sequence
  44.          * 1, 2, 4, 8, 16, 25, 36, 49, 64, 81, 100 ...
  45.          */
  46.  
  47.         if(n <= 4)
  48.                 return 1 << n;  /* Binary exponential back off */
  49.         else
  50.                 return n * n;   /* Quadratic back off */
  51. }
  52.  
  53.