forked from KolibriOS/kolibrios
FTPC 0.12: notify user when connect failed, added timeout when receiving commands from the server.
git-svn-id: svn://kolibrios.org@4918 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8819b2de58
commit
7ad048ca42
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
format binary as ""
|
format binary as ""
|
||||||
|
|
||||||
|
TIMEOUT = 3 ; seconds
|
||||||
|
|
||||||
BUFFERSIZE = 4096
|
BUFFERSIZE = 4096
|
||||||
|
|
||||||
STATUS_CONNECTING = 0
|
STATUS_CONNECTING = 0
|
||||||
@ -47,8 +49,8 @@ include 'usercommands.inc'
|
|||||||
include 'servercommands.inc'
|
include 'servercommands.inc'
|
||||||
|
|
||||||
start:
|
start:
|
||||||
; disable all events
|
; disable all events except network event
|
||||||
mcall 40, 0
|
mcall 40, EV_STACK
|
||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -114,6 +116,8 @@ resolve:
|
|||||||
; connect to the server
|
; connect to the server
|
||||||
invoke con_write_asciiz, str_connect
|
invoke con_write_asciiz, str_connect
|
||||||
mcall connect, [socketnum], sockaddr1, 18
|
mcall connect, [socketnum], sockaddr1, 18
|
||||||
|
cmp eax, -1
|
||||||
|
je error_connect
|
||||||
mov [status], STATUS_CONNECTING
|
mov [status], STATUS_CONNECTING
|
||||||
; Tell the user we're waiting for the server now.
|
; Tell the user we're waiting for the server now.
|
||||||
invoke con_write_asciiz, str_waiting
|
invoke con_write_asciiz, str_waiting
|
||||||
@ -133,12 +137,22 @@ wait_for_servercommand:
|
|||||||
|
|
||||||
; receive socket data
|
; receive socket data
|
||||||
.receive:
|
.receive:
|
||||||
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
|
mcall 26, 9
|
||||||
inc eax
|
add eax, TIMEOUT*100
|
||||||
jz error_socket
|
mov [timeout], eax
|
||||||
dec eax
|
.receive_loop:
|
||||||
jz wait_for_servercommand
|
mcall 23, 50 ; Wait for event with timeout
|
||||||
|
mcall 26, 9
|
||||||
|
cmp eax, [timeout]
|
||||||
|
jge error_timeout
|
||||||
|
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT
|
||||||
|
test eax, eax
|
||||||
|
jnz .got_data
|
||||||
|
cmp ebx, EWOULDBLOCK
|
||||||
|
jne error_socket
|
||||||
|
jmp .receive_loop
|
||||||
|
|
||||||
|
.got_data:
|
||||||
mov [offset], 0
|
mov [offset], 0
|
||||||
|
|
||||||
; extract commands, copy them to "s" buffer
|
; extract commands, copy them to "s" buffer
|
||||||
@ -299,7 +313,15 @@ open_dataconnection: ; only passive for now..
|
|||||||
invoke con_set_flags ; reset color
|
invoke con_set_flags ; reset color
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
error_connect:
|
||||||
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
|
invoke con_write_asciiz, str_err_connect
|
||||||
|
jmp wait_for_keypress
|
||||||
|
|
||||||
|
error_timeout:
|
||||||
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
|
invoke con_write_asciiz, str_err_timeout
|
||||||
|
jmp wait_for_keypress
|
||||||
|
|
||||||
error_socket:
|
error_socket:
|
||||||
invoke con_set_flags, 0x0c ; print errors in red
|
invoke con_set_flags, 0x0c ; print errors in red
|
||||||
@ -328,7 +350,7 @@ exit:
|
|||||||
|
|
||||||
; data
|
; data
|
||||||
str_title db 'FTP client',0
|
str_title db 'FTP client',0
|
||||||
str_welcome db 'FTP client for KolibriOS v0.11',10
|
str_welcome db 'FTP client for KolibriOS v0.12',10
|
||||||
db 10
|
db 10
|
||||||
db 'Please enter ftp server address.',10,0
|
db 'Please enter ftp server address.',10,0
|
||||||
|
|
||||||
@ -337,6 +359,8 @@ str_resolve db 'Resolving ',0
|
|||||||
str_newline db 10,0
|
str_newline db 10,0
|
||||||
str_err_resolve db 10,'Name resolution failed.',10,0
|
str_err_resolve db 10,'Name resolution failed.',10,0
|
||||||
str_err_socket db 10,'Socket error.',10,0
|
str_err_socket db 10,'Socket error.',10,0
|
||||||
|
str_err_timeout db 10,'Timeout - no response from server.',10,0
|
||||||
|
str_err_connect db 10,'Cannot connect to the server.',10,0
|
||||||
str8 db ' (',0
|
str8 db ' (',0
|
||||||
str9 db ')',10,0
|
str9 db ')',10,0
|
||||||
str_push db 'Push any key to continue.',0
|
str_push db 'Push any key to continue.',0
|
||||||
@ -422,6 +446,8 @@ offset dd ?
|
|||||||
size dd ?
|
size dd ?
|
||||||
operation dd ?
|
operation dd ?
|
||||||
|
|
||||||
|
timeout dd ?
|
||||||
|
|
||||||
filestruct:
|
filestruct:
|
||||||
.subfn dd ?
|
.subfn dd ?
|
||||||
.offset dd ?
|
.offset dd ?
|
||||||
|
Loading…
Reference in New Issue
Block a user