--- parser3/src/targets/cgi/parser3.C 2026/10/09 21:38:52 1.377 +++ parser3/src/targets/cgi/parser3.C 2026/10/18 22:42:43 1.382 @@ -5,7 +5,7 @@ Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.377 2026/10/09 21:38:52 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.382 2026/10/18 22:42:43 moko Exp $"; #include "pa_config_includes.h" @@ -18,6 +18,7 @@ volatile const char * IDENT_PARSER3_C="$ #include "pa_vconsole.h" #include "pa_sapi_info.h" #include "pa_code_cache.h" +#include "pa_websocket.h" #ifdef _MSC_VER #include @@ -70,7 +71,7 @@ const char *parser3_log_filespec() { // const char* slog=log_filespec; if(!slog) { - static char log_spec[MAX_STRING + 12 /* '/parser3.log' */]; + static THREAD_LOCAL char log_spec[MAX_STRING + 12 /* '/parser3.log' */]; pa_strncpy(log_spec, filespec_4log, MAX_STRING); if(char* log_dir_pos=strrchr(log_spec, '/')){ @@ -99,14 +100,20 @@ static void pa_log(const char* fmt, va_l // prefix time_t t=time(0); - if(const char* stamp=ctime(&t)) { // never saw that +#ifdef _MSC_VER + const char* stamp=ctime(&t); // the buffer is per thread +#else + char stamp_buffer[32]; // the buffer of ctime() is shared by the threads + const char* stamp=ctime_r(&t, stamp_buffer); +#endif + if(stamp) { // never saw that if(size_t len=strlen(stamp)) // saw once stamp being ="" fprintf(f, "[%.*s] [%u] ", (int)len-1, stamp, (unsigned int)pa_get_thread_id() ); } // message char buf[MAX_LOG_STRING]; - size_t size=vsnprintf(buf, MAX_LOG_STRING, fmt, args); + size_t size=pa_vsnprintf(buf, MAX_LOG_STRING, fmt, args); size=remove_crlf(buf, buf+size); fwrite(buf, size, 1, f); @@ -147,7 +154,7 @@ void SAPI::die(const char* fmt, ...) { // inform user, second vsnprintf va_start(args, fmt); char message[MAX_STRING]; - vsnprintf(message, MAX_STRING, fmt, args); + pa_vsnprintf(message, MAX_STRING, fmt, args); SAPI::send_error(sapi_info_4log ? *sapi_info_4log : *sapi_info, message); exit(1); @@ -330,7 +337,7 @@ static void config_handler(SAPI_Info &in #ifdef CODE_CACHE Code_cache_manager::start(); #endif - r.core(config_filespec, false, String::Empty); + r.core(config_filespec, String::Empty); #ifdef CODE_CACHE Code_cache_manager::finish(r); #endif @@ -358,8 +365,10 @@ static void connection_handler(SAPI_Info // prepare to process request Request r(info, request_info, String::Language(String::L_HTML|String::L_OPTIMIZE_BIT)); + WebSocket websocket(connection); + r.websocket=&websocket; // process the request - r.core(config_filespec, strcasecmp(request_info.method, "HEAD")==0, main_method_name, &httpd_class_name); + r.core(config_filespec, main_method_name, &httpd_class_name); } catch(const Exception& e) { // exception in connection handling SAPI::log(info, "%s", e.comment()); const char* status = info.exception_http_status(e.type()); @@ -373,6 +382,8 @@ DWORD WINAPI connection_thread(void *arg #else static void *connection_thread(void *arg){ #endif + Temp_gc_references gc_references; // for pointers GC does not see, the very start of the thread + HTTPD_Connection &connection=*(HTTPD_Connection*)arg; SAPI_Info_HTTPD info(connection); @@ -539,7 +550,7 @@ static void real_parser_handler(bool cgi // initing ::request ptr for signal handlers RequestController rc(&r); // process the request - r.core(locate_config(config_filespec, parser3_filespec), strcasecmp(request_info.method, "HEAD")==0); + r.core(locate_config(config_filespec, parser3_filespec)); // clearing ::request in RequestController destructor to prevent signal handlers from accessing invalid memory // then the request is destroyed, before the libraries are unloaded: its pool cleanups call them (memcached) } @@ -615,6 +626,8 @@ static void usage(const char* message=NU } int main(int argc, char *argv[]) { + Temp_gc_references gc_references; // for pointers GC does not see + #ifdef PA_DEBUG_CGI_ENTRY_EXIT pa_log("main: entry"); #endif