Subversion Repositories Kolibri OS

Rev

Rev 3556 | Rev 5013 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  Part of the TCP/IP network stack for KolibriOS                 ;;
  7. ;;                                                                 ;;
  8. ;;   Written by hidnplayr@kolibrios.org                            ;;
  9. ;;                                                                 ;;
  10. ;;    Based on the code of 4.4BSD                                  ;;
  11. ;;                                                                 ;;
  12. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  13. ;;             Version 2, June 1991                                ;;
  14. ;;                                                                 ;;
  15. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  16.  
  17. $Revision: 3143 $
  18.  
  19. timer_flag_retransmission       = 1 shl 0
  20. timer_flag_keepalive            = 1 shl 1
  21. timer_flag_2msl                 = 1 shl 2
  22. timer_flag_persist              = 1 shl 3
  23. timer_flag_wait                 = 1 shl 4
  24.  
  25.  
  26. ;----------------------
  27. ; 160 ms timer
  28. ;----------------------
  29. macro   TCP_timer_160ms {
  30.  
  31. local   .loop
  32. local   .exit
  33.  
  34.         mov     ebx, net_sockets
  35.   .loop:
  36.         mov     ebx, [ebx + SOCKET.NextPtr]
  37.         test    ebx, ebx
  38.         jz      .exit
  39.  
  40.         cmp     [ebx + SOCKET.Domain], AF_INET4
  41.         jne     .loop
  42.         cmp     [ebx + SOCKET.Protocol], IP_PROTO_TCP
  43.         jne     .loop
  44.         test    [ebx + TCP_SOCKET.t_flags], TF_DELACK
  45.         jz      .loop
  46.  
  47.         and     [ebx + TCP_SOCKET.t_flags], not (TF_DELACK)
  48.  
  49.         push    ebx
  50.         mov     cl, TH_ACK
  51.         call    TCP_respond
  52. ;        and     [ebx + TCP_SOCKET.t_flags], TF_ACKNOW   ;;
  53. ;        mov     eax, ebx                                ;;
  54. ;        call    TCP_output                              ;;
  55.         pop     ebx
  56.  
  57.         jmp     .loop
  58.  
  59.   .exit:
  60.  
  61. }
  62.  
  63.  
  64. ;----------------------
  65. ; 640 ms timer
  66. ;----------------------
  67. macro   TCP_timer_640ms {                       ; TODO: implement timed wait timer!
  68.  
  69. local   .loop
  70. local   .exit
  71.  
  72. ; Update TCP sequence number
  73.  
  74.         add     [TCP_sequence_num], 64000
  75.  
  76. ; scan through all the active TCP sockets, decrementing ALL timers
  77. ; When a timer reaches zero, we'll check wheter it was active or not
  78.  
  79.         mov     eax, net_sockets
  80.   .loop:
  81.         mov     eax, [eax + SOCKET.NextPtr]
  82.   .check_only:
  83.         or      eax, eax
  84.         jz      .exit
  85.  
  86.         cmp     [eax + SOCKET.Domain], AF_INET4
  87.         jne     .loop
  88.  
  89.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  90.         jne     .loop
  91.  
  92.         inc     [eax + TCP_SOCKET.t_idle]
  93.  
  94.         dec     [eax + TCP_SOCKET.timer_retransmission]
  95.         jnz     .check_more2
  96.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission
  97.         jz      .check_more2
  98.  
  99.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax
  100.  
  101.         push    eax
  102.         call    TCP_output
  103.         pop     eax
  104.  
  105.   .check_more2:
  106.         dec     [eax + TCP_SOCKET.timer_keepalive]
  107.         jnz     .check_more3
  108.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive
  109.         jz      .check_more3
  110.  
  111.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax
  112.  
  113.         cmp     [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
  114.         ja      .dont_kill
  115.  
  116.         push    eax
  117.         call    TCP_disconnect
  118.         pop     eax
  119.         jmp     .loop
  120.  
  121.   .dont_kill:
  122.         test    [eax + SOCKET.options], SO_KEEPALIVE
  123.         jz      .reset_keepalive
  124.  
  125.         push    eax
  126.         mov     ebx, eax
  127.         xor     cl, cl
  128.         call    TCP_respond     ; send keepalive
  129.         pop     eax
  130.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
  131.         jmp     .check_more3
  132.  
  133.   .reset_keepalive:
  134.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
  135.  
  136.   .check_more3:
  137.         dec     [eax + TCP_SOCKET.timer_timed_wait]
  138.         jnz     .check_more5
  139.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_2msl
  140.         jz      .check_more5
  141.  
  142.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax
  143.  
  144.   .check_more5:
  145.         dec     [eax + TCP_SOCKET.timer_persist]
  146.         jnz     .loop
  147.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_persist
  148.         jz      .loop
  149.  
  150.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
  151.  
  152.         call    TCP_set_persist
  153.         mov     [eax + TCP_SOCKET.t_force], 1
  154.         push    eax
  155.         call    TCP_output
  156.         pop     eax
  157.         mov     [eax + TCP_SOCKET.t_force], 0
  158.  
  159.         jmp     .loop
  160.   .exit:
  161.  
  162. }
  163.  
  164.  
  165.  
  166. ; eax = socket
  167.  
  168. TCP_cancel_timers:
  169.  
  170.         mov     [eax + TCP_SOCKET.timer_flags], 0
  171.  
  172.         ret