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