Subversion Repositories Kolibri OS

Rev

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