Subversion Repositories Kolibri OS

Rev

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