Rev 3556 | Rev 4850 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3600 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2013. 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 | |||
17 | $Revision: 3143 $ |
||
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 | |||
3545 | hidnplayr | 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] |
||
3600 | hidnplayr | 37 | test ebx, ebx |
3545 | hidnplayr | 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 |
||
3600 | hidnplayr | 46 | |
3545 | hidnplayr | 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 | ;---------------------- |
||
65 | ; 640 ms timer |
||
66 | ;---------------------- |
||
3600 | hidnplayr | 67 | macro TCP_timer_640ms { ; TODO: implement timed wait timer! |
3545 | hidnplayr | 68 | |
69 | local .loop |
||
70 | local .exit |
||
71 | |||
72 | ; Update TCP sequence number |
||
73 | |||
74 | add [TCP_sequence_num], 64000 |
||
75 | |||
76 | ; scan through all the active TCP sockets, decrementing ALL timers |
||
3600 | hidnplayr | 77 | ; When a timer reaches zero, we'll check wheter it was active or not |
3545 | hidnplayr | 78 | |
79 | mov eax, net_sockets |
||
80 | .loop: |
||
81 | mov eax, [eax + SOCKET.NextPtr] |
||
82 | .check_only: |
||
83 | or eax, eax |
||
84 | jz .exit |
||
85 | |||
86 | cmp [eax + SOCKET.Domain], AF_INET4 |
||
87 | jne .loop |
||
88 | |||
89 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
||
90 | jne .loop |
||
91 | |||
92 | inc [eax + TCP_SOCKET.t_idle] |
||
3600 | hidnplayr | 93 | |
3545 | hidnplayr | 94 | dec [eax + TCP_SOCKET.timer_retransmission] |
95 | jnz .check_more2 |
||
3600 | hidnplayr | 96 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
97 | jz .check_more2 |
||
3545 | hidnplayr | 98 | |
3556 | hidnplayr | 99 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax |
3545 | hidnplayr | 100 | |
101 | push eax |
||
102 | call TCP_output |
||
103 | pop eax |
||
104 | |||
105 | .check_more2: |
||
106 | dec [eax + TCP_SOCKET.timer_keepalive] |
||
107 | jnz .check_more3 |
||
3600 | hidnplayr | 108 | test [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive |
109 | jz .check_more3 |
||
3545 | hidnplayr | 110 | |
3556 | hidnplayr | 111 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax |
3545 | hidnplayr | 112 | |
113 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
||
114 | ja .dont_kill |
||
115 | |||
116 | push eax |
||
117 | call TCP_disconnect |
||
118 | pop eax |
||
119 | jmp .loop |
||
120 | |||
121 | .dont_kill: |
||
122 | test [eax + SOCKET.options], SO_KEEPALIVE |
||
123 | jz .reset_keepalive |
||
124 | |||
125 | push eax |
||
126 | mov ebx, eax |
||
127 | xor cl, cl |
||
128 | call TCP_respond ; send keepalive |
||
129 | pop eax |
||
130 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval |
||
131 | jmp .check_more3 |
||
132 | |||
133 | .reset_keepalive: |
||
134 | mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle |
||
135 | |||
136 | .check_more3: |
||
137 | dec [eax + TCP_SOCKET.timer_timed_wait] |
||
138 | jnz .check_more5 |
||
3600 | hidnplayr | 139 | test [eax + TCP_SOCKET.timer_flags], timer_flag_2msl |
140 | jz .check_more5 |
||
3545 | hidnplayr | 141 | |
3556 | hidnplayr | 142 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax |
3545 | hidnplayr | 143 | |
144 | .check_more5: |
||
145 | dec [eax + TCP_SOCKET.timer_persist] |
||
146 | jnz .loop |
||
3600 | hidnplayr | 147 | test [eax + TCP_SOCKET.timer_flags], timer_flag_persist |
148 | jz .loop |
||
3545 | hidnplayr | 149 | |
3556 | hidnplayr | 150 | DEBUGF DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax |
3545 | hidnplayr | 151 | |
152 | call TCP_set_persist |
||
153 | mov [eax + TCP_SOCKET.t_force], 1 |
||
154 | push eax |
||
155 | call TCP_output |
||
156 | pop eax |
||
157 | mov [eax + TCP_SOCKET.t_force], 0 |
||
158 | |||
159 | jmp .loop |
||
160 | .exit: |
||
161 | |||
162 | } |
||
163 | |||
164 | |||
165 | |||
166 | ; eax = socket |
||
167 | |||
168 | TCP_cancel_timers: |
||
169 | |||
3600 | hidnplayr | 170 | mov [eax + TCP_SOCKET.timer_flags], 0 |
3545 | hidnplayr | 171 | |
172 | ret |