From 261bcf35ff6e511840f0b63db0118bb6db620f13 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sun, 29 Aug 2021 17:37:31 +0000 Subject: [PATCH] FTPC: improved error handeling in wait_for_servercommand git-svn-id: svn://kolibrios.org@9164 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/network/ftpc/ftpc.asm | 41 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/programs/network/ftpc/ftpc.asm b/programs/network/ftpc/ftpc.asm index f88620b534..a77286934b 100644 --- a/programs/network/ftpc/ftpc.asm +++ b/programs/network/ftpc/ftpc.asm @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2013-2018. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2013-2021. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;; ftpc.asm - FTP client for KolibriOS ;; @@ -353,26 +353,36 @@ wait_for_servercommand: ;/////////////////////////////////////////////////////// add ecx, esi jmp .byteloop -; receive socket data +; receive socket data with timeout .receive: mcall 26, 9 add eax, TIMEOUT*100 mov [timeout], eax - .receive_loop: - mcall 23, 50 ; Wait for event with timeout - mcall 26, 9 - cmp eax, [timeout] - jl @f - mov eax, str_err_timeout - jmp error - @@: mcall recv, [controlsocket], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT - test eax, eax - jnz .got_data + .again: + mcall recv, [controlsocket], buf_buffer1, BUFFERSIZE, MSG_DONTWAIT + cmp eax, 0 + jg .got_data + je .closed cmp ebx, EWOULDBLOCK - je @f + jne .sock_err + mcall 26, 9 + mov ebx, [timeout] + sub ebx, eax + jle .timeout + mcall 23 ; Wait for event with timeout + jmp .again + + .sock_err: mov eax, str_err_recv jmp error - @@: jmp .receive_loop + + .closed: + mov eax, str_err_closed + jmp error + + .timeout: + mov eax, str_err_timeout + jmp error .got_data: mov [offset], 0 @@ -750,7 +760,7 @@ exit2: ; data str_title db 'FTP client for KolibriOS',0 -str_welcome db 'FTP client for KolibriOS v0.15b',10 +str_welcome db 'FTP client for KolibriOS v0.16',10 db 10,0 str_srv_addr db 'Please enter ftp server address.',10,0 @@ -758,6 +768,7 @@ str_prompt db '> ',0 str_resolve db 'Resolving ',0 str_newline db 10,0 str_err_resolve db 10,'Name resolution failed.',10,0 +str_err_closed db 10,'The connection was closed by the remote end',10,0 str_err_socket db 10,'[75,0 socket]: Error creating a socket',10,0 str_err_bind db 10,'[75,2 bind]: Error binding to socket',10,0 str_err_listen db 10,'[75,3 listen]: Cannot accept incoming connections',10,0