TCP: correctly close connection.

git-svn-id: svn://kolibrios.org@4366 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-12-15 21:27:22 +00:00
parent fe46d27eaf
commit e2ec33712e
5 changed files with 45 additions and 57 deletions

View File

@ -714,6 +714,11 @@ SOCKET_close:
call TCP_usrclosed
test eax, eax
jz @f
call TCP_output ; If connection is not closed yet, send the FIN
@@:
ret
@ -2196,7 +2201,7 @@ SOCKET_check_owner:
;
; Kernel calls this function when a certain process ends
; This function will check if the process had any open sockets
; And update them accordingly
; And update them accordingly (clean up)
;
; IN: edx = pid
; OUT: /
@ -2242,7 +2247,7 @@ SOCKET_process_end:
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
jne .free
call TCP_close
call TCP_disconnect
jmp .closed
.free:
@ -2347,20 +2352,9 @@ SOCKET_is_disconnected:
and [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
or [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
je .tcp
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
je .udp
jmp SOCKET_notify
.tcp:
.udp:
mov [eax + UDP_SOCKET.LocalPort], 0 ; UDP and TCP structs store localport at the same offset
mov [eax + UDP_SOCKET.RemotePort], 0
jmp SOCKET_notify
;-----------------------------------------------------------------

View File

@ -567,12 +567,13 @@ endl
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction failed\n"
; Calculate receive window size
push edx
mov eax, SOCKETBUFFSIZE
mov eax, SOCKET_MAXDATA
sub eax, [ebx + STREAM_SOCKET.rcv.size]
DEBUGF DEBUG_NETWORK_VERBOSE, "Space in receive buffer=%d\n", eax
mov edx, [ebx + TCP_SOCKET.RCV_ADV]
sub edx, [ebx + TCP_SOCKET.RCV_NXT]
DEBUGF DEBUG_NETWORK_VERBOSE, "Current advertised window=%d\n", edx
cmp eax, edx
jg @f
mov eax, edx
@ -1189,12 +1190,9 @@ endl
call mutex_unlock
pop ebx
push ebx
mov eax, ebx
call TCP_disconnect
pop ebx
jmp .destroy_new_socket
call TCP_close
jmp .drop_no_socket
.ack_tw:
mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL

View File

@ -32,7 +32,7 @@ locals
temp_bits db ?
endl
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket=%x\n", eax
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket=%x state=%u\n", eax, [eax + TCP_SOCKET.t_state]
push eax
lea ecx, [eax + SOCKET.mutex]

View File

@ -171,8 +171,35 @@ TCP_drop:
;-------------------------
;
; TCP_disconnect
;
; IN: eax = socket ptr
; OUT: eax = socket ptr / 0
;
;-------------------------
align 4
TCP_disconnect:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_disconnect: %x\n", eax
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
jb TCP_close ; Connection not yet synchronised, just get rid of the socket
; TODO: implement LINGER
call SOCKET_is_disconnecting
call TCP_usrclosed
test eax, eax
jz @f
push eax
call TCP_output
pop eax
@@:
ret
;-------------------------
@ -180,7 +207,7 @@ TCP_drop:
; TCP_close
;
; IN: eax = socket ptr
; OUT: eax = socket ptr
; OUT: /
;
;-------------------------
align 4
@ -192,7 +219,9 @@ TCP_close:
;;; TODO: update slow start threshold
call SOCKET_is_disconnected
;; call SOCKET_free
call SOCKET_free
xor eax, eax
ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;;
@ -57,7 +57,6 @@ TCP_usrclosed:
.wait1:
mov [eax + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1
; TODO: set timer?
pop ebx
ret
@ -68,7 +67,6 @@ TCP_usrclosed:
.disc:
call SOCKET_is_disconnected
; TODO: set timer?
.ret:
pop ebx
ret
@ -203,34 +201,3 @@ TCP_connect:
xor eax, eax
ret
;-------------------------
;
; TCP_disconnect
;
; IN: eax = socket ptr
; OUT: eax = socket ptr
;
;-------------------------
align 4
TCP_disconnect:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_disconnect: %x\n", eax
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
jb TCP_close
; TODO: implement LINGER ?
call SOCKET_is_disconnecting
call TCP_usrclosed
push eax
call TCP_output
pop eax
ret