--- parser3/src/main/pa_http.C 2020/12/20 19:58:54 1.115 +++ parser3/src/main/pa_http.C 2021/11/08 11:44:20 1.119 @@ -14,7 +14,7 @@ #include "pa_vfile.h" #include "pa_random.h" -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.115 2020/12/20 19:58:54 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.119 2021/11/08 11:44:20 moko Exp $" IDENT_PA_HTTP_H; #ifdef _MSC_VER #include @@ -264,7 +264,10 @@ static sigjmp_buf timeout_env; static void timeout_handler(int /*sig*/){ siglongjmp(timeout_env, 1); } -#define ALARM(value) alarm(value) + +#define PA_NO_THREADS (HTTPD_Server::mode != HTTPD_Server::MULTITHREADED) + +#define ALARM(value) if(PA_NO_THREADS) alarm(value) #else #define ALARM(value) #endif @@ -276,8 +279,8 @@ static int http_request(HTTP_response& r volatile int sock=-1; // to prevent makeing it register variable, because it will be clobbered by longjmp [thanks gcc warning] #ifdef PA_USE_ALARM - signal(SIGALRM, timeout_handler); - if(sigsetjmp(timeout_env, 1)) { + if(PA_NO_THREADS) signal(SIGALRM, timeout_handler); + if(PA_NO_THREADS && sigsetjmp(timeout_env, 1)) { // duplicating closesocket to make code more simple for old compilers if(sock>=0) closesocket(sock); @@ -739,7 +742,7 @@ File_read_http_result pa_internal_file_r throw Exception(PARSER_RUNTIME, &connect_string, "does not start with http://"); //never current+=7; - strncpy(host, current, sizeof(host)-1); host[sizeof(host)-1]=0; + pa_strncpy(host, current, sizeof(host)); char* host_uri=lsplit(host, '/'); uri=host_uri?current+(host_uri-1-host):"/"; char* port_cstr=lsplit(host, ':'); @@ -1036,15 +1039,10 @@ enum HTTPD_request_state { ssize_t HTTPD_request::pa_recv(int sockfd, char *buffer, size_t len){ LOG(pa_log("httpd [%d] recv %d appending to %d ...", sockfd, len, length)); - if(HTTPD_Server::mode == HTTPD_Server::MULTITHREADED){ - ssize_t result=recv(sockfd, buffer, len, 0); - LOG(pa_log("httpd [%d] recv got %d bytes", sockfd, result)); - return result; - } #ifdef PA_USE_ALARM - signal(SIGALRM, timeout_handler); - if(sigsetjmp(timeout_env, 1)) { + if(PA_NO_THREADS) signal(SIGALRM, timeout_handler); + if(PA_NO_THREADS && sigsetjmp(timeout_env, 1)) { LOG(pa_log("httpd [%d] recv got %d sec timeout", sockfd, pa_httpd_timeout)); if(length) // timeout on "void" connection is normal throw Exception("httpd.timeout", 0, "timeout occurred while receiving request"); @@ -1239,10 +1237,10 @@ void HTTPD_Server::set_mode(const String else if (value == "threaded") mode = MULTITHREADED; #endif #ifdef _MSC_VER - else throw Exception("httpd.mode", &value, "$main:HTTPD.mode must be 'sequental' or 'threaded'"); + else throw Exception("httpd.mode", &value, "$MAIN:HTTPD.mode must be 'sequental' or 'threaded'"); #else else if (value == "parallel") mode = PARALLEL; - else throw Exception("httpd.mode", &value, "$main:HTTPD.mode must be 'sequental', 'parallel' or 'threaded'"); + else throw Exception("httpd.mode", &value, "$MAIN:HTTPD.mode must be 'sequental', 'parallel' or 'threaded'"); #endif } @@ -1251,7 +1249,7 @@ int HTTPD_Server::bind(const char *host_ port = strchr(host_port, ':'); const char *host = NULL; - if(port ){ + if(port){ if(port > host_port) host = pa_strdup(host_port, port - host_port); port += 1;