From 7cade993e90401b729c26b8967d803aff32056d9 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sun, 13 Oct 2013 21:35:17 +0000 Subject: [PATCH] kernel: wait 3 seconds for TCP connection to be established, timeout after that. telnet: print error message when socket could not be opened. git-svn-id: svn://kolibrios.org@4020 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/network/socket.inc | 18 ++++++++++++++---- programs/network/telnet/telnet.asm | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/trunk/network/socket.inc b/kernel/trunk/network/socket.inc index a5db19dad5..5a30e1b2e6 100644 --- a/kernel/trunk/network/socket.inc +++ b/kernel/trunk/network/socket.inc @@ -608,22 +608,32 @@ align 4 .block: test [eax + SOCKET.options], SO_NONBLOCK - jz .loop + jz .waitforit mov dword[esp+20], EWOULDBLOCK mov dword[esp+32], -1 ret + .waitforit: + push eax + stdcall timer_hs, 300, 0, .wake, eax ; FIXME: make timeout a constant + pop eax + .loop: - cmp [eax + TCP_SOCKET.t_state], TCPS_CLOSED - je .fail + cmp [eax + SOCKET.errorcode], 0 + jne .fail cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED je .established - ja .fail call SOCKET_block jmp .loop + .wake: + mov eax, [esp+4] + mov [eax + SOCKET.errorcode], ETIMEDOUT + call SOCKET_notify.unblock + ret 4 + .fail: mov eax, [eax + SOCKET.errorcode] mov [esp+20], eax diff --git a/programs/network/telnet/telnet.asm b/programs/network/telnet/telnet.asm index 60db096d7c..ef86534fc6 100644 --- a/programs/network/telnet/telnet.asm +++ b/programs/network/telnet/telnet.asm @@ -160,6 +160,8 @@ resolve: mov [socketnum], eax mcall connect, [socketnum], sockaddr1, 18 + test eax, eax + jnz socket_err mcall 40, 1 shl 7 ; + 7 call [con_cls]