--- parser3/src/main/pa_common.C 2004/12/10 07:41:06 1.198 +++ parser3/src/main/pa_common.C 2005/08/09 08:14:51 1.205 @@ -1,11 +1,11 @@ /** @file Parser: commonly functions. - Copyright(c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) + Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_COMMON_C="$Date: 2004/12/10 07:41:06 $"; +static const char * const IDENT_COMMON_C="$Date: 2005/08/09 08:14:51 $"; #include "pa_common.h" #include "pa_exception.h" @@ -165,7 +165,9 @@ static int http_read_response(char*& res while(true) { char buf[MAX_STRING*10]; ssize_t received_size=recv(sock, buf, sizeof(buf), 0); - if(received_size<=0) { + if(received_size==0) + break; + if(received_size<0) { if(int no=pa_socks_errno()) throw Exception("http.timeout", 0, @@ -207,7 +209,7 @@ static int http_read_response(char*& res #ifdef PA_USE_ALARM static sigjmp_buf timeout_env; -static void timeout_handler(int sig){ +static void timeout_handler(int /*sig*/){ siglongjmp(timeout_env, 1); } #endif @@ -222,19 +224,20 @@ static int http_request(char*& response, 0, "zero hostname"); //never + volatile // to prevent makeing it register variable, because it will be clobbered by longjmp [thanks gcc warning] + int sock=-1; #ifdef PA_USE_ALARM signal(SIGALRM, timeout_handler); #endif - int sock=-1; #ifdef PA_USE_ALARM if(sigsetjmp(timeout_env, 1)) { // stupid gcc [2.95.4] generated bad code // which failed to handle sigsetjmp+throw: crashed inside of pre-throw code. - // rewritten simplier [though duplicating closesocket code] + // rewritten simplier [athough duplicating closesocket code] if(sock>=0) closesocket(sock); throw Exception("http.timeout", - origin_string, + 0, "timeout occured while retrieving document"); return 0; // never } else { @@ -256,23 +259,17 @@ static int http_request(char*& response, "can not make socket: %s (%d)", pa_socks_strerr(no), no); } -#ifdef SO_DONTLINGER - int dont_linger = 0; - setsockopt(sock, SOL_SOCKET, SO_DONTLINGER, (const char *)&dont_linger, sizeof(dont_linger)); -#else // To enable SO_DONTLINGER (that is, disable SO_LINGER) // l_onoff should be set to zero and setsockopt should be called linger dont_linger={0,0}; setsockopt(sock, SOL_SOCKET, SO_LINGER, (const char *)&dont_linger, sizeof(dont_linger)); -#endif -#if defined(SO_SNDTIMEO) || defined(SO_RCVTIMEO) +#ifdef WIN32 +// SO_*TIMEO can be defined in .h but not implemlemented in protocol, +// failing subsequently with Option not supported by protocol (99) message +// could not suppress that, so leaving this only for win32 int timeout_ms=timeout_secs*1000; -#endif -#ifdef SO_SNDTIMEO setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout_ms, sizeof(timeout_ms)); -#endif -#ifdef SO_RCVTIMEO setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout_ms, sizeof(timeout_ms)); #endif @@ -738,6 +735,11 @@ File_read_result file_read(Request_chars File_read_result result={false, 0, 0, 0}; #ifdef PA_HTTP if(file_spec.starts_with("http://")) { + if(offset || count) + throw Exception("parser.runtime", + 0, + "offset and load options are not supported for HTTP:// file load"); + // fail on read problem File_read_http_result http=file_read_http(charsets, file_spec, as_text, params); result.success=true; @@ -847,7 +849,7 @@ bool file_read_action_under_lock(const S } } -static void create_dir_for_file(const String& file_spec) { +void create_dir_for_file(const String& file_spec) { size_t pos_after=1; size_t pos_before; while((pos_before=file_spec.pos('/', pos_after))!=STRING_NOT_FOUND) {