Rev 2955 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1763 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3143 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
1763 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
3143 | hidnplayr | 6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
1763 | hidnplayr | 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1733 | hidnplayr | 16 | |
1763 | hidnplayr | 17 | $Revision: 3143 $ |
18 | |||
1733 | hidnplayr | 19 | ;---------------------- |
20 | ; 160 ms timer |
||
21 | ;---------------------- |
||
2879 | hidnplayr | 22 | macro TCP_timer_160ms { |
1733 | hidnplayr | 23 | |
2879 | hidnplayr | 24 | local .loop |
25 | local .exit |
||
1733 | hidnplayr | 26 | |
2879 | hidnplayr | 27 | mov ebx, net_sockets |
1733 | hidnplayr | 28 | .loop: |
2879 | hidnplayr | 29 | mov ebx, [ebx + SOCKET.NextPtr] |
30 | or ebx, ebx |
||
31 | jz .exit |
||
1733 | hidnplayr | 32 | |
2879 | hidnplayr | 33 | cmp [ebx + SOCKET.Domain], AF_INET4 |
34 | jne .loop |
||
1733 | hidnplayr | 35 | |
2879 | hidnplayr | 36 | cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP |
37 | jne .loop |
||
1733 | hidnplayr | 38 | |
2879 | hidnplayr | 39 | test [ebx + TCP_SOCKET.t_flags], TF_DELACK |
40 | jz .loop |
||
41 | and [ebx + TCP_SOCKET.t_flags], not (TF_DELACK) |
||
1733 | hidnplayr | 42 | |
2879 | hidnplayr | 43 | push ebx |
44 | mov cl, TH_ACK |
||
3143 | hidnplayr | 45 | call TCP_respond |
2936 | hidnplayr | 46 | ; and [ebx + TCP_SOCKET.t_flags], TF_ACKNOW ;; |
47 | ; mov eax, ebx ;; |
||
48 | ; call TCP_output ;; |
||
2879 | hidnplayr | 49 | pop ebx |
1733 | hidnplayr | 50 | |
2879 | hidnplayr | 51 | jmp .loop |
1733 | hidnplayr | 52 | |
53 | .exit: |
||
54 | |||
55 | } |
||
56 | |||
57 | |||
58 | ;---------------------- |
||
59 | ; 640 ms timer |
||
60 | ;---------------------- |
||
2879 | hidnplayr | 61 | macro TCP_timer_640ms { |
1733 | hidnplayr | 62 | |
2879 | hidnplayr | 63 | local .loop |
64 | local .exit |
||
1733 | hidnplayr | 65 | |
66 | ; Update TCP sequence number |
||
67 | |||
2879 | hidnplayr | 68 | add [TCP_sequence_num], 64000 |
1733 | hidnplayr | 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 | |||
2879 | hidnplayr | 73 | mov eax, net_sockets |
1733 | hidnplayr | 74 | .loop: |
2879 | hidnplayr | 75 | mov eax, [eax + SOCKET.NextPtr] |
1733 | hidnplayr | 76 | .check_only: |
2879 | hidnplayr | 77 | or eax, eax |
78 | jz .exit |
||
1733 | hidnplayr | 79 | |
2879 | hidnplayr | 80 | cmp [eax + SOCKET.Domain], AF_INET4 |
81 | jne .loop |
||
1733 | hidnplayr | 82 | |
2879 | hidnplayr | 83 | cmp [eax + SOCKET.Protocol], IP_PROTO_TCP |
84 | jne .loop |
||
1733 | hidnplayr | 85 | |
2879 | hidnplayr | 86 | inc [eax + TCP_SOCKET.t_idle] |
87 | dec [eax + TCP_SOCKET.timer_retransmission] |
||
88 | jnz .check_more2 |
||
1733 | hidnplayr | 89 | |
2879 | hidnplayr | 90 | DEBUGF 1,"socket %x: Retransmission timer expired\n", eax |
1733 | hidnplayr | 91 | |
2879 | hidnplayr | 92 | push eax |
93 | call TCP_output |
||
94 | pop eax |
||
1733 | hidnplayr | 95 | |
96 | .check_more2: |
||
2879 | hidnplayr | 97 | dec [eax + TCP_SOCKET.timer_keepalive] |
98 | jnz .check_more3 |
||
1733 | hidnplayr | 99 | |
2879 | hidnplayr | 100 | DEBUGF 1,"socket %x: Keepalive expired\n", eax |
1733 | hidnplayr | 101 | |
3143 | hidnplayr | 102 | cmp [eax + TCP_SOCKET.state], TCPS_ESTABLISHED |
103 | ja .dont_kill |
||
104 | |||
2936 | hidnplayr | 105 | push eax |
2879 | hidnplayr | 106 | call TCP_disconnect |
2936 | hidnplayr | 107 | pop eax |
2879 | hidnplayr | 108 | jmp .loop |
1733 | hidnplayr | 109 | |
3143 | hidnplayr | 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 | |||
1733 | hidnplayr | 125 | .check_more3: |
2879 | hidnplayr | 126 | dec [eax + TCP_SOCKET.timer_timed_wait] |
127 | jnz .check_more5 |
||
1733 | hidnplayr | 128 | |
2879 | hidnplayr | 129 | DEBUGF 1,"socket %x: 2MSL timer expired\n", eax |
1733 | hidnplayr | 130 | |
131 | .check_more5: |
||
2879 | hidnplayr | 132 | dec [eax + TCP_SOCKET.timer_persist] |
133 | jnz .loop |
||
1733 | hidnplayr | 134 | |
2879 | hidnplayr | 135 | DEBUGF 1,"socket %x: persist timer expired\n", eax |
1733 | hidnplayr | 136 | |
2955 | hidnplayr | 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 | |||
2879 | hidnplayr | 144 | jmp .loop |
1733 | hidnplayr | 145 | .exit: |
146 | |||
1773 | hidnplayr | 147 | } |
148 | |||
149 | |||
150 | |||
151 | ; eax = socket |
||
152 | |||
153 | TCP_cancel_timers: |
||
154 | |||
2879 | hidnplayr | 155 | push eax edi |
1773 | hidnplayr | 156 | |
2879 | hidnplayr | 157 | lea edi, [eax + TCP_SOCKET.timer_retransmission] |
158 | xor eax, eax |
||
159 | stosd |
||
160 | stosd |
||
161 | stosd |
||
162 | stosd |
||
163 | stosd |
||
1773 | hidnplayr | 164 | |
2879 | hidnplayr | 165 | pop edi eax |
1773 | hidnplayr | 166 | |
167 | |||
2879 | hidnplayr | 168 | ret |