From 3ae524970961100575f949f0bcdccb23ed32cde4 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 11 Nov 2013 12:29:54 +0000 Subject: [PATCH] Timeout for HTTP library git-svn-id: svn://kolibrios.org@4206 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/libraries/http/http.asm | 43 ++++++++++++++++-------- programs/develop/libraries/http/http.inc | 3 +- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/programs/develop/libraries/http/http.asm b/programs/develop/libraries/http/http.asm index bb51cd769a..f865f026cd 100644 --- a/programs/develop/libraries/http/http.asm +++ b/programs/develop/libraries/http/http.asm @@ -19,6 +19,7 @@ URLMAXLEN = 65535 BUFFERSIZE = 4096 + TIMEOUT = 1000 ; in 1/100 s __DEBUG__ = 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.content_length], 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 @@ -387,6 +394,7 @@ endl DEBUGF 1, "Request has been sent to server.\n" HTTP_init_buffer [buffer], [socketnum] + ; mov eax, [buffer] ret ; return buffer ptr @@ -423,6 +431,11 @@ proc HTTP_process identifier ;////////////////////////////////////////////////// je .check_socket DEBUGF 1, "Received %u bytes\n", eax + push eax + mcall 29, 9 + mov [ebp + http_msg.timestamp], eax + pop eax + ; Update pointers mov edi, [ebp + http_msg.write_ptr] add [ebp + http_msg.write_ptr], eax @@ -712,34 +725,36 @@ proc HTTP_process identifier ;////////////////////////////////////////////////// .check_socket: cmp ebx, EWOULDBLOCK - je .need_more_data - DEBUGF 1, "ERROR: socket error %u\n", ebx + jne .socket_error - or [ebp + http_msg.flags], FLAG_SOCKET_ERROR - and [ebp + http_msg.flags], not FLAG_CONNECTED - mcall close, [ebp + http_msg.socket] - .connection_closed: - popa - xor eax, eax - ret + mcall 29, 9 + sub eax, TIMEOUT + cmp eax, [ebp + http_msg.timestamp] + ja .need_more_data + DEBUGF 1, "ERROR: timeout\n" + or [ebp + http_msg.flags], FLAG_TIMEOUT_ERROR + jmp .disconnect .invalid_header: pop eax DEBUGF 1, "ERROR: invalid header\n" or [ebp + http_msg.flags], FLAG_INVALID_HEADER - and [ebp + http_msg.flags], not FLAG_CONNECTED - mcall close, [ebp + http_msg.socket] - popa - xor eax, eax - ret + jmp .disconnect .no_ram_pop: pop eax .no_ram: DEBUGF 1, "ERROR: out of RAM\n" 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 mcall close, [ebp + http_msg.socket] + .connection_closed: popa xor eax, eax ret diff --git a/programs/develop/libraries/http/http.inc b/programs/develop/libraries/http/http.inc index 4b9d8a32db..e99cad4777 100644 --- a/programs/develop/libraries/http/http.inc +++ b/programs/develop/libraries/http/http.inc @@ -24,6 +24,7 @@ FLAG_CONNECTED = 1 shl 5 FLAG_INVALID_HEADER = 1 shl 16 FLAG_NO_RAM = 1 shl 17 FLAG_SOCKET_ERROR = 1 shl 18 +FLAG_TIMEOUT_ERROR = 1 shl 19 struc http_msg { .socket dd ? @@ -31,7 +32,7 @@ struc http_msg { .write_ptr dd ? .buffer_length dd ? .chunk_ptr dd ? - + .timestamp dd ? .status dd ? .header_length dd ? .content_length dd ?