Subversion Repositories Kolibri OS

Rev

Rev 6916 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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