Timeout for HTTP library

git-svn-id: svn://kolibrios.org@4206 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-11-11 12:29:54 +00:00
parent 0c94d22080
commit 3ae5249709
2 changed files with 31 additions and 15 deletions

View File

@ -19,6 +19,7 @@
URLMAXLEN = 65535 URLMAXLEN = 65535
BUFFERSIZE = 4096 BUFFERSIZE = 4096
TIMEOUT = 1000 ; in 1/100 s
__DEBUG__ = 1 __DEBUG__ = 1
__DEBUG_LEVEL__ = 1 __DEBUG_LEVEL__ = 1
@ -66,6 +67,12 @@ macro HTTP_init_buffer buffer, socketnum {
mov [eax + http_msg.header_length], 0 mov [eax + http_msg.header_length], 0
mov [eax + http_msg.content_length], 0 mov [eax + http_msg.content_length], 0
mov [eax + http_msg.content_received], 0 mov [eax + http_msg.content_received], 0
push eax ebp
mov ebp, eax
mcall 29, 9
mov [ebp + http_msg.timestamp], eax
pop ebp eax
} }
section '.flat' code readable align 16 section '.flat' code readable align 16
@ -387,6 +394,7 @@ endl
DEBUGF 1, "Request has been sent to server.\n" DEBUGF 1, "Request has been sent to server.\n"
HTTP_init_buffer [buffer], [socketnum] HTTP_init_buffer [buffer], [socketnum]
; mov eax, [buffer] ; mov eax, [buffer]
ret ; return buffer ptr ret ; return buffer ptr
@ -423,6 +431,11 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
je .check_socket je .check_socket
DEBUGF 1, "Received %u bytes\n", eax DEBUGF 1, "Received %u bytes\n", eax
push eax
mcall 29, 9
mov [ebp + http_msg.timestamp], eax
pop eax
; Update pointers ; Update pointers
mov edi, [ebp + http_msg.write_ptr] mov edi, [ebp + http_msg.write_ptr]
add [ebp + http_msg.write_ptr], eax add [ebp + http_msg.write_ptr], eax
@ -712,34 +725,36 @@ proc HTTP_process identifier ;//////////////////////////////////////////////////
.check_socket: .check_socket:
cmp ebx, EWOULDBLOCK cmp ebx, EWOULDBLOCK
je .need_more_data jne .socket_error
DEBUGF 1, "ERROR: socket error %u\n", ebx
or [ebp + http_msg.flags], FLAG_SOCKET_ERROR mcall 29, 9
and [ebp + http_msg.flags], not FLAG_CONNECTED sub eax, TIMEOUT
mcall close, [ebp + http_msg.socket] cmp eax, [ebp + http_msg.timestamp]
.connection_closed: ja .need_more_data
popa DEBUGF 1, "ERROR: timeout\n"
xor eax, eax or [ebp + http_msg.flags], FLAG_TIMEOUT_ERROR
ret jmp .disconnect
.invalid_header: .invalid_header:
pop eax pop eax
DEBUGF 1, "ERROR: invalid header\n" DEBUGF 1, "ERROR: invalid header\n"
or [ebp + http_msg.flags], FLAG_INVALID_HEADER or [ebp + http_msg.flags], FLAG_INVALID_HEADER
and [ebp + http_msg.flags], not FLAG_CONNECTED jmp .disconnect
mcall close, [ebp + http_msg.socket]
popa
xor eax, eax
ret
.no_ram_pop: .no_ram_pop:
pop eax pop eax
.no_ram: .no_ram:
DEBUGF 1, "ERROR: out of RAM\n" DEBUGF 1, "ERROR: out of RAM\n"
or [ebp + http_msg.flags], FLAG_NO_RAM or [ebp + http_msg.flags], FLAG_NO_RAM
jmp .disconnect
.socket_error:
DEBUGF 1, "ERROR: socket error %u\n", ebx
or [ebp + http_msg.flags], FLAG_SOCKET_ERROR
.disconnect:
and [ebp + http_msg.flags], not FLAG_CONNECTED and [ebp + http_msg.flags], not FLAG_CONNECTED
mcall close, [ebp + http_msg.socket] mcall close, [ebp + http_msg.socket]
.connection_closed:
popa popa
xor eax, eax xor eax, eax
ret ret

View File

@ -24,6 +24,7 @@ FLAG_CONNECTED = 1 shl 5
FLAG_INVALID_HEADER = 1 shl 16 FLAG_INVALID_HEADER = 1 shl 16
FLAG_NO_RAM = 1 shl 17 FLAG_NO_RAM = 1 shl 17
FLAG_SOCKET_ERROR = 1 shl 18 FLAG_SOCKET_ERROR = 1 shl 18
FLAG_TIMEOUT_ERROR = 1 shl 19
struc http_msg { struc http_msg {
.socket dd ? .socket dd ?
@ -31,7 +32,7 @@ struc http_msg {
.write_ptr dd ? .write_ptr dd ?
.buffer_length dd ? .buffer_length dd ?
.chunk_ptr dd ? .chunk_ptr dd ?
.timestamp dd ?
.status dd ? .status dd ?
.header_length dd ? .header_length dd ?
.content_length dd ? .content_length dd ?