Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2015. 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: 6011 $
  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. macro   tcp_timer_160ms {
  27.  
  28. local   .loop
  29. local   .exit
  30.  
  31.         mov     ebx, net_sockets
  32.   .loop:
  33.         mov     ebx, [ebx + SOCKET.NextPtr]
  34.         test    ebx, ebx
  35.         jz      .exit
  36.  
  37.         cmp     [ebx + SOCKET.Domain], AF_INET4
  38.         jne     .loop
  39.         cmp     [ebx + SOCKET.Protocol], IP_PROTO_TCP
  40.         jne     .loop
  41.         test    [ebx + TCP_SOCKET.t_flags], TF_DELACK
  42.         jz      .loop
  43.  
  44.         and     [ebx + TCP_SOCKET.t_flags], not (TF_DELACK)
  45.  
  46.         push    ebx
  47.         mov     cl, TH_ACK
  48.         call    tcp_respond
  49.         pop     ebx
  50.  
  51.         inc     [TCPS_delack]                   ; update stats
  52.  
  53.         jmp     .loop
  54.  
  55.   .exit:
  56.  
  57. }
  58.  
  59.  
  60. align 4
  61. proc tcp_timer_640ms
  62.  
  63.         xor     esi, esi
  64.         mov     ecx, MANUAL_DESTROY
  65.         call    create_event
  66.         mov     [TCP_timer1_event], eax
  67.  
  68.   .wait:
  69.         mov     eax, [TCP_timer1_event]
  70.         mov     ebx, [eax + EVENT.id]
  71.         call    wait_event
  72.  
  73. ; Update TCP sequence number
  74.  
  75.         add     [TCP_sequence_num], 64000
  76.  
  77. ; Scan through all the active TCP sockets, decrementing all active timers
  78. ; When a timer reaches zero, run its handler.
  79.  
  80.         mov     eax, net_sockets
  81.   .loop:
  82.         mov     eax, [eax + SOCKET.NextPtr]
  83.   .check_only:
  84.         or      eax, eax
  85.         jz      .wait
  86.  
  87.         cmp     [eax + SOCKET.Domain], AF_INET4
  88.         jne     .loop
  89.  
  90.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  91.         jne     .loop
  92.  
  93.         inc     [eax + TCP_SOCKET.t_idle]
  94.  
  95.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission
  96.         jz      .check_more2
  97.         dec     [eax + TCP_SOCKET.timer_retransmission]
  98.         jnz     .check_more2
  99.  
  100.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax
  101.  
  102.         push    eax
  103.         call    tcp_output
  104.         pop     eax
  105.  
  106.   .check_more2:
  107.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive
  108.         jz      .check_more3
  109.         dec     [eax + TCP_SOCKET.timer_keepalive]
  110.         jnz     .check_more3
  111.  
  112.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax
  113.  
  114.         cmp     [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
  115.         ja      .dont_kill
  116.  
  117.         push    eax
  118.         call    tcp_disconnect
  119.         pop     eax
  120.         jmp     .loop
  121.  
  122.   .dont_kill:
  123.         test    [eax + SOCKET.options], SO_KEEPALIVE
  124.         jz      .reset_keepalive
  125.  
  126.         push    eax
  127.         mov     ebx, eax
  128.         xor     cl, cl
  129.         call    tcp_respond                     ; send keepalive
  130.         pop     eax
  131.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
  132.         jmp     .check_more3
  133.  
  134.   .reset_keepalive:
  135.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
  136.  
  137.   .check_more3:
  138.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_2msl
  139.         jz      .check_more5
  140.         dec     [eax + TCP_SOCKET.timer_timed_wait]
  141.         jnz     .check_more5
  142.  
  143.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax
  144.  
  145.   .check_more5:
  146.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_persist
  147.         jz      .check_more6
  148.         dec     [eax + TCP_SOCKET.timer_persist]
  149.         jnz     .check_more6
  150.  
  151.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
  152.  
  153.         call    tcp_set_persist
  154.         mov     [eax + TCP_SOCKET.t_force], 1
  155.         push    eax
  156.         call    tcp_output
  157.         pop     eax
  158.         mov     [eax + TCP_SOCKET.t_force], 0
  159.  
  160.   .check_more6:
  161.         test    [eax + TCP_SOCKET.timer_flags], timer_flag_wait
  162.         jz      .loop
  163.         dec     [eax + TCP_SOCKET.timer_timed_wait]
  164.         jnz     .loop
  165.  
  166.         DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: timed wait timer expired\n", eax
  167.  
  168.         push    [eax + SOCKET.NextPtr]
  169.         call    tcp_close
  170.         pop     eax
  171.  
  172.         jmp     .check_only
  173.  
  174. endp
  175.  
  176.  
  177. ;-----------------------------------------------------------------;
  178. ;                                                                 ;
  179. ; TCP_cancel_timers                                               ;
  180. ;                                                                 ;
  181. ;   IN: eax = socket                                              ;
  182. ;                                                                 ;
  183. ;  OUT: /                                                         ;
  184. ;                                                                 ;
  185. ;-----------------------------------------------------------------;
  186. align 4
  187. tcp_cancel_timers:
  188.  
  189.         mov     [eax + TCP_SOCKET.timer_flags], 0
  190.  
  191.         ret