From 645e347dffafd39ac88a1345563d04c5321d844c Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Fri, 13 Jul 2012 16:24:41 +0000 Subject: [PATCH] Implemented proper closing/disconnecting for TCP sockets. git-svn-id: svn://kolibrios.org@2869 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/socket.inc | 2 +- kernel/branches/net/network/tcp_subr.inc | 76 +++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index f5af9fe168..b9adbd514c 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -1749,7 +1749,7 @@ SOCKET_process_end: .tcp: push [ebx + SOCKET.NextPtr] mov eax, ebx - call TCP_close + call TCP_disconnect pop ebx jmp .test_socket diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index a7ad3ee927..b9ae34bc70 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -179,23 +179,97 @@ TCP_drop: align 4 TCP_close: - DEBUGF 1,"TCP_close\n" + DEBUGF 1,"TCP_close: %x\n", eax ;;; TODO: update RTT and mean deviation ;;; TODO: update slow start threshold ;;; TODO: release connection resources call SOCKET_is_disconnected + call SOCKET_free ret +;------------------------- +; +; TCP_disconnect +; +; IN: eax = socket ptr +; OUT: eax = socket ptr +; +;------------------------- +align 4 +TCP_disconnect: + + DEBUGF 1,"TCP_disconnect\n" + + cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED + jb TCP_close + + +; TODO: implement LINGER ? + + call SOCKET_is_disconnecting + call TCP_usrclosed + call TCP_output + + ret +;------------------------- +; +; TCP_usrclose +; +; IN: eax = socket ptr +; +;------------------------- +align 4 +TCP_usrclosed: + + push ebx + mov ebx, [eax + TCP_SOCKET.t_state] + mov ebx, dword [.switch + ebx*4] + jmp ebx + + .switch: + + dd .close ; TCPS_CLOSED + dd .close ; TCPS_LISTEN + dd .close ; TCPS_SYN_SENT + dd .wait1 ; TCPS_SYN_RECEIVED + dd .wait1 ; TCPS_ESTABLISHED + dd .last_ack ; TCPS_CLOSE_WAIT + dd .ret ; TCPS_FIN_WAIT_1 + dd .ret ; TCPS_CLOSING + dd .ret ; TCPS_LAST_ACK + dd .disc ; TCPS_FIN_WAIT_2 + dd .disc ; TCPS_TIMED_WAIT + .close: + pop ebx + mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED + call TCP_close + ret + + .wait1: + pop ebx + mov [eax + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1 + ret + + .last_ack: + pop ebx + mov [eax + TCP_SOCKET.t_state], TCPS_LAST_ACK + ret + + .disc: + call SOCKET_is_disconnected + .ret: + pop ebx + ret ;-------------------------