Bugixes and improvements for closing TCP sockets.

git-svn-id: svn://kolibrios.org@3652 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-06-13 08:22:37 +00:00
parent de3f768cbf
commit 52556729d6
4 changed files with 42 additions and 22 deletions

View File

@ -729,7 +729,6 @@ SOCKET_close:
mov dword [esp+32], 0 ; The socket exists, so we will succeed in closing it. mov dword [esp+32], 0 ; The socket exists, so we will succeed in closing it.
.socket:
or [eax + SOCKET.options], SO_NONBLOCK ; Mark the socket as non blocking, we dont want it to block any longer! or [eax + SOCKET.options], SO_NONBLOCK ; Mark the socket as non blocking, we dont want it to block any longer!
test [eax + SOCKET.state], SS_BLOCKED ; Is the socket still in blocked state? test [eax + SOCKET.state], SS_BLOCKED ; Is the socket still in blocked state?
@ -1924,16 +1923,16 @@ SOCKET_free:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: %x\n", eax DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: %x\n", eax
call SOCKET_check
jz .error
push ebx
pusha pusha
mov ecx, socket_mutex mov ecx, socket_mutex
call mutex_lock call mutex_lock
popa popa
call SOCKET_check
jz .error
push ebx
pusha pusha
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_lock call mutex_lock
@ -1951,6 +1950,7 @@ SOCKET_free:
mov eax, ebx mov eax, ebx
.no_tcp: .no_tcp:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: freeing socket %x\n", eax
push eax ; this will be passed to kernel_free push eax ; this will be passed to kernel_free
mov ebx, [eax + SOCKET.NextPtr] mov ebx, [eax + SOCKET.NextPtr]
mov eax, [eax + SOCKET.PrevPtr] mov eax, [eax + SOCKET.PrevPtr]
@ -1970,14 +1970,15 @@ SOCKET_free:
call kernel_free call kernel_free
pop ebx pop ebx
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
.error:
pusha pusha
mov ecx, socket_mutex mov ecx, socket_mutex
call mutex_unlock call mutex_unlock
popa popa
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
.error:
ret ret
;------------------------------------ ;------------------------------------
@ -2125,11 +2126,6 @@ SOCKET_check:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
pusha
mov ecx, socket_mutex
call mutex_lock
popa
push ebx push ebx
mov ebx, net_sockets mov ebx, net_sockets
@ -2145,11 +2141,6 @@ SOCKET_check:
test eax, eax test eax, eax
pop ebx pop ebx
pusha
mov ecx, socket_mutex
call mutex_unlock
popa
ret ret
@ -2229,7 +2220,19 @@ SOCKET_process_end:
popa popa
pusha pusha
call SOCKET_close.socket cmp [eax + SOCKET.Domain], AF_INET4
jne .free
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
jne .free
call TCP_close
jmp .closed
.free:
call SOCKET_free
.closed:
popa popa
pusha pusha

View File

@ -1170,9 +1170,17 @@ TCP_process_input:
.ack_la: .ack_la:
jnc .ack_processed jnc .ack_processed
push ebx
lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock
pop ebx
push ebx
mov eax, ebx mov eax, ebx
call TCP_disconnect call TCP_disconnect
jmp .drop pop ebx
jmp .destroy_new_socket
.ack_tw: .ack_tw:
mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL mov [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL

View File

@ -35,6 +35,8 @@ TCP_output:
call mutex_lock call mutex_lock
pop eax pop eax
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_output: socket locked\n"
; We'll detect the length of the data to be transmitted, and flags to be used ; We'll detect the length of the data to be transmitted, and flags to be used
; If there is some data, or any critical controls to send (SYN / RST), then transmit ; If there is some data, or any critical controls to send (SYN / RST), then transmit
; Otherwise, investigate further ; Otherwise, investigate further
@ -216,6 +218,7 @@ TCP_output:
mov ebx, TCP_max_win mov ebx, TCP_max_win
shl ebx, cl shl ebx, cl
pop ecx pop ecx
cmp ebx, ecx cmp ebx, ecx
jb @f jb @f
mov ebx, ecx mov ebx, ecx
@ -571,6 +574,8 @@ TCP_send:
;-------------- ;--------------
; unlock socket ; unlock socket
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_send: unlocking socket 0x%x\n", eax
push eax push eax
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
@ -607,7 +612,8 @@ TCP_send:
.send_error: .send_error:
add esp, 8 add esp, 4
pop eax
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock

View File

@ -97,6 +97,9 @@ TCP_disconnect:
call SOCKET_is_disconnecting call SOCKET_is_disconnecting
call TCP_usrclosed call TCP_usrclosed
push eax
call TCP_output call TCP_output
pop eax
ret ret