home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / TCPTIMER.C < prev    next >
C/C++ Source or Header  |  1991-12-18  |  1KB  |  53 lines

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