SOCKET_connect: better error handling.

git-svn-id: svn://kolibrios.org@4025 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-10-14 07:08:51 +00:00
parent 45f1ce4315
commit e3504571ad
2 changed files with 38 additions and 11 deletions

View File

@ -498,6 +498,12 @@ SOCKET_connect:
cmp esi, 8 cmp esi, 8
jb .invalid jb .invalid
cmp [eax + SOCKET.state], SS_ISCONNECTING
je .already
test [eax + SOCKET.options], SO_ACCEPTCON
jnz .notsupp
cmp word [edx], AF_INET4 cmp word [edx], AF_INET4
je .af_inet4 je .af_inet4
@ -511,10 +517,20 @@ SOCKET_connect:
mov dword[esp+32], -1 mov dword[esp+32], -1
ret ret
.already:
mov dword[esp+20], EALREADY
mov dword[esp+32], -1
ret
.eisconn:
mov dword[esp+20], EISCONN
mov dword[esp+32], -1
ret
.af_inet4: .af_inet4:
cmp [eax + IP_SOCKET.LocalIP], 0 cmp [eax + IP_SOCKET.LocalIP], 0
jne @f jne @f
push [IP_LIST + 4] ; FIXME !i!i!i! push [IP_LIST + 4] ; FIXME: use correct local IP
pop [eax + IP_SOCKET.LocalIP] pop [eax + IP_SOCKET.LocalIP]
@@: @@:
@ -539,6 +555,7 @@ align 4
call mutex_lock call mutex_lock
popa popa
; Fill in remote port and IP, overwriting eventually previous values
pushw [edx + 2] pushw [edx + 2]
pop [eax + UDP_SOCKET.RemotePort] pop [eax + UDP_SOCKET.RemotePort]
@ -559,11 +576,16 @@ align 4
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_unlock call mutex_unlock
call SOCKET_is_connected
mov dword[esp+32], 0 mov dword[esp+32], 0
ret ret
align 4 align 4
.tcp: .tcp:
test [eax + SOCKET.state], SS_ISCONNECTED
jnz .eisconn
pusha pusha
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_lock call mutex_lock
@ -589,7 +611,6 @@ align 4
mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
TCP_sendseqinit eax TCP_sendseqinit eax
; mov [ebx + TCP_SOCKET.timer_retransmission], ;; todo: create macro to set retransmission timer
mov ebx, eax mov ebx, eax
lea eax, [ebx + STREAM_SOCKET.snd] lea eax, [ebx + STREAM_SOCKET.snd]
@ -598,13 +619,14 @@ align 4
lea eax, [ebx + STREAM_SOCKET.rcv] lea eax, [ebx + STREAM_SOCKET.rcv]
call SOCKET_ring_create ; TODO: same here call SOCKET_ring_create ; TODO: same here
pusha push ebx
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock call mutex_unlock
popa pop eax
push ebx call SOCKET_is_connecting
mov eax, ebx
push eax
call TCP_output call TCP_output
pop eax pop eax
@ -612,8 +634,8 @@ align 4
test [eax + SOCKET.options], SO_NONBLOCK test [eax + SOCKET.options], SO_NONBLOCK
jz .waitforit jz .waitforit
mov dword[esp+20], EWOULDBLOCK
mov dword[esp+32], -1 mov dword[esp+32], -1
mov dword[esp+20], EINPROGRESS
ret ret
.waitforit: .waitforit:
@ -635,17 +657,20 @@ align 4
.timeout: .timeout:
mov eax, [esp+4] mov eax, [esp+4]
mov [eax + SOCKET.errorcode], ETIMEDOUT mov [eax + SOCKET.errorcode], ETIMEDOUT
and [eax + SOCKET.state], not SS_ISCONNECTING
call SOCKET_notify.unblock call SOCKET_notify.unblock
ret 4 ret 4
.fail: .fail:
mov eax, [eax + SOCKET.errorcode] mov eax, [eax + SOCKET.errorcode]
mov [eax + SOCKET.errorcode], 0 ; Clear the error, we only need to send it to the caller once
mov [esp+20], eax mov [esp+20], eax
mov dword[esp+32], -1 mov dword[esp+32], -1
ret ret
.established: .established:
stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect] stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect]
mov dword[esp+20], EISCONN
mov dword[esp+32], 0 mov dword[esp+32], 0
ret ret
@ -2405,10 +2430,10 @@ SOCKET_is_connecting:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax
and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) and [eax + SOCKET.state], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
or [eax + SOCKET.options], SS_ISCONNECTING or [eax + SOCKET.state], SS_ISCONNECTING
jmp SOCKET_notify ret

View File

@ -115,6 +115,7 @@ MAX_backlog = 20 ; maximum backlog for stream sockets
; Error Codes ; Error Codes
ENOBUFS = 1 ENOBUFS = 1
EINPROGRESS = 2
EOPNOTSUPP = 4 EOPNOTSUPP = 4
EWOULDBLOCK = 6 EWOULDBLOCK = 6
ENOTCONN = 9 ENOTCONN = 9
@ -125,6 +126,7 @@ ENOMEM = 18
EADDRINUSE = 20 EADDRINUSE = 20
ECONNREFUSED = 61 ECONNREFUSED = 61
ECONNRESET = 52 ECONNRESET = 52
EISCONN = 56
ETIMEDOUT = 60 ETIMEDOUT = 60
ECONNABORTED = 53 ECONNABORTED = 53