Subversion Repositories Kolibri OS

Rev

Rev 5976 | Rev 6916 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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