Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. 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: 3143 $
  18.  
  19. ;----------------------
  20. ; 160 ms timer
  21. ;----------------------
  22. macro   TCP_timer_160ms {
  23.  
  24. local   .loop
  25. local   .exit
  26.  
  27.         mov     ebx, net_sockets
  28.   .loop:
  29.         mov     ebx, [ebx + SOCKET.NextPtr]
  30.         or      ebx, ebx
  31.         jz      .exit
  32.  
  33.         cmp     [ebx + SOCKET.Domain], AF_INET4
  34.         jne     .loop
  35.  
  36.         cmp     [ebx + SOCKET.Protocol], IP_PROTO_TCP
  37.         jne     .loop
  38.  
  39.         test    [ebx + TCP_SOCKET.t_flags], TF_DELACK
  40.         jz      .loop
  41.         and     [ebx + TCP_SOCKET.t_flags], not (TF_DELACK)
  42.  
  43.         push    ebx
  44.         mov     cl, TH_ACK
  45.         call    TCP_respond
  46. ;        and     [ebx + TCP_SOCKET.t_flags], TF_ACKNOW   ;;
  47. ;        mov     eax, ebx                                ;;
  48. ;        call    TCP_output                              ;;
  49.         pop     ebx
  50.  
  51.         jmp     .loop
  52.  
  53.   .exit:
  54.  
  55. }
  56.  
  57.  
  58. ;----------------------
  59. ; 640 ms timer
  60. ;----------------------
  61. macro   TCP_timer_640ms {
  62.  
  63. local   .loop
  64. local   .exit
  65.  
  66. ; Update TCP sequence number
  67.  
  68.         add     [TCP_sequence_num], 64000
  69.  
  70. ; scan through all the active TCP sockets, decrementing ALL timers
  71. ; timers do not have the chance to wrap because the keepalive timer will kill the socket when it expires
  72.  
  73.         mov     eax, net_sockets
  74.   .loop:
  75.         mov     eax, [eax + SOCKET.NextPtr]
  76.   .check_only:
  77.         or      eax, eax
  78.         jz      .exit
  79.  
  80.         cmp     [eax + SOCKET.Domain], AF_INET4
  81.         jne     .loop
  82.  
  83.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  84.         jne     .loop
  85.  
  86.         inc     [eax + TCP_SOCKET.t_idle]
  87.         dec     [eax + TCP_SOCKET.timer_retransmission]
  88.         jnz     .check_more2
  89.  
  90.         DEBUGF  1,"socket %x: Retransmission timer expired\n", eax
  91.  
  92.         push    eax
  93.         call    TCP_output
  94.         pop     eax
  95.  
  96.   .check_more2:
  97.         dec     [eax + TCP_SOCKET.timer_keepalive]
  98.         jnz     .check_more3
  99.  
  100.         DEBUGF  1,"socket %x: Keepalive expired\n", eax
  101.  
  102.         cmp     [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
  103.         ja      .dont_kill
  104.  
  105.         push    eax
  106.         call    TCP_disconnect
  107.         pop     eax
  108.         jmp     .loop
  109.  
  110.   .dont_kill:
  111.         test    [eax + SOCKET.options], SO_KEEPALIVE
  112.         jz      .reset_keepalive
  113.  
  114.         push    eax
  115.         mov     ebx, eax
  116.         xor     cl, cl
  117.         call    TCP_respond     ; send keepalive
  118.         pop     eax
  119.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
  120.         jmp     .check_more3
  121.  
  122.   .reset_keepalive:
  123.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
  124.  
  125.   .check_more3:
  126.         dec     [eax + TCP_SOCKET.timer_timed_wait]
  127.         jnz     .check_more5
  128.  
  129.         DEBUGF  1,"socket %x: 2MSL timer expired\n", eax
  130.  
  131.   .check_more5:
  132.         dec     [eax + TCP_SOCKET.timer_persist]
  133.         jnz     .loop
  134.  
  135.         DEBUGF  1,"socket %x: persist timer expired\n", eax
  136.  
  137.         call    TCP_set_persist
  138.         mov     [eax + TCP_SOCKET.t_force], 1
  139.         push    eax
  140.         call    TCP_output
  141.         pop     eax
  142.         mov     [eax + TCP_SOCKET.t_force], 0
  143.  
  144.         jmp     .loop
  145.   .exit:
  146.  
  147. }
  148.  
  149.  
  150.  
  151. ; eax = socket
  152.  
  153. TCP_cancel_timers:
  154.  
  155.         push    eax edi
  156.  
  157.         lea     edi, [eax + TCP_SOCKET.timer_retransmission]
  158.         xor     eax, eax
  159.         stosd
  160.         stosd
  161.         stosd
  162.         stosd
  163.         stosd
  164.  
  165.         pop     edi eax
  166.  
  167.  
  168.         ret