Subversion Repositories Kolibri OS

Rev

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