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