Subversion Repositories Kolibri OS

Rev

Rev 5013 | Rev 5442 | 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: 5363 $
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
 
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
 
5013 hidnplayr 64
align 4
65
proc TCP_timer_640ms            ; TODO: implement timed wait timer!
3545 hidnplayr 66
 
5013 hidnplayr 67
        xor     esi, esi
68
        mov     ecx, MANUAL_DESTROY
69
        call    create_event
70
        mov     [TCP_timer1_event], eax
3545 hidnplayr 71
 
5013 hidnplayr 72
  .wait:
73
        mov     eax, [TCP_timer1_event]
74
        mov     ebx, [eax + EVENT.id]
75
        call    wait_event
76
 
3545 hidnplayr 77
; Update TCP sequence number
78
 
79
        add     [TCP_sequence_num], 64000
80
 
81
; scan through all the active TCP sockets, decrementing ALL timers
3600 hidnplayr 82
; When a timer reaches zero, we'll check wheter it was active or not
3545 hidnplayr 83
 
84
        mov     eax, net_sockets
85
  .loop:
86
        mov     eax, [eax + SOCKET.NextPtr]
87
  .check_only:
88
        or      eax, eax
5013 hidnplayr 89
        jz      .wait
3545 hidnplayr 90
 
91
        cmp     [eax + SOCKET.Domain], AF_INET4
92
        jne     .loop
93
 
94
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
95
        jne     .loop
96
 
97
        inc     [eax + TCP_SOCKET.t_idle]
3600 hidnplayr 98
 
3545 hidnplayr 99
        dec     [eax + TCP_SOCKET.timer_retransmission]
100
        jnz     .check_more2
3600 hidnplayr 101
        test    [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission
102
        jz      .check_more2
3545 hidnplayr 103
 
3556 hidnplayr 104
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Retransmission timer expired\n", eax
3545 hidnplayr 105
 
106
        push    eax
107
        call    TCP_output
108
        pop     eax
109
 
110
  .check_more2:
111
        dec     [eax + TCP_SOCKET.timer_keepalive]
112
        jnz     .check_more3
3600 hidnplayr 113
        test    [eax + TCP_SOCKET.timer_flags], timer_flag_keepalive
114
        jz      .check_more3
3545 hidnplayr 115
 
3556 hidnplayr 116
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: Keepalive expired\n", eax
3545 hidnplayr 117
 
118
        cmp     [eax + TCP_SOCKET.state], TCPS_ESTABLISHED
119
        ja      .dont_kill
120
 
121
        push    eax
122
        call    TCP_disconnect
123
        pop     eax
124
        jmp     .loop
125
 
126
  .dont_kill:
127
        test    [eax + SOCKET.options], SO_KEEPALIVE
128
        jz      .reset_keepalive
129
 
130
        push    eax
131
        mov     ebx, eax
132
        xor     cl, cl
133
        call    TCP_respond     ; send keepalive
134
        pop     eax
135
        mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
136
        jmp     .check_more3
137
 
138
  .reset_keepalive:
139
        mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
140
 
141
  .check_more3:
142
        dec     [eax + TCP_SOCKET.timer_timed_wait]
143
        jnz     .check_more5
3600 hidnplayr 144
        test    [eax + TCP_SOCKET.timer_flags], timer_flag_2msl
145
        jz      .check_more5
3545 hidnplayr 146
 
3556 hidnplayr 147
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: 2MSL timer expired\n", eax
3545 hidnplayr 148
 
149
  .check_more5:
150
        dec     [eax + TCP_SOCKET.timer_persist]
151
        jnz     .loop
3600 hidnplayr 152
        test    [eax + TCP_SOCKET.timer_flags], timer_flag_persist
153
        jz      .loop
3545 hidnplayr 154
 
3556 hidnplayr 155
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socket %x: persist timer expired\n", eax
3545 hidnplayr 156
 
157
        call    TCP_set_persist
158
        mov     [eax + TCP_SOCKET.t_force], 1
159
        push    eax
160
        call    TCP_output
161
        pop     eax
162
        mov     [eax + TCP_SOCKET.t_force], 0
163
 
164
        jmp     .loop
165
 
5013 hidnplayr 166
endp
3545 hidnplayr 167
 
168
 
169
 
170
; eax = socket
171
 
172
TCP_cancel_timers:
173
 
3600 hidnplayr 174
        mov     [eax + TCP_SOCKET.timer_flags], 0
3545 hidnplayr 175
 
176
        ret