Subversion Repositories Kolibri OS

Rev

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