--- parser3/src/targets/cgi/parser3.C 2020/12/10 23:04:17 1.326 +++ parser3/src/targets/cgi/parser3.C 2020/12/15 13:08:17 1.328 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.326 2020/12/10 23:04:17 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.328 2020/12/15 13:08:17 moko Exp $"; #include "pa_config_includes.h" @@ -21,6 +21,13 @@ volatile const char * IDENT_PARSER3_C="$ #include #include #include + +extern "C" HANDLE WINAPI GC_CreateThread(LPSECURITY_ATTRIBUTES, DWORD, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD); + +#else + +extern "C" int GC_pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void * /* arg */); + #endif // defines @@ -348,7 +355,11 @@ static void connection_handler(SAPI_Info } } +#ifdef _MSC_VER +DWORD WINAPI connection_thread(void *arg){ +#else static void *connection_thread(void *arg){ +#endif HTTPD_Connection &connection=*(HTTPD_Connection*)arg; SAPI_Info_HTTPD info(connection); @@ -359,7 +370,7 @@ static void *connection_thread(void *arg } delete(&connection); - return NULL; + return 0; } static void httpd_mode() { @@ -367,25 +378,30 @@ static void httpd_mode() { int sock = HTTPD_Server::bind(httpd_host_port); -#if 0 +#ifdef SIGCHLD signal(SIGCHLD, SIG_IGN); +#endif +#ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); - -// HTTPD_Server::mode = HTTPD_Server::PARALLEL; -// HTTPD_Server::mode = HTTPD_Server::MULTITHREADED; #endif while(1){ +#ifndef _MSC_VER pid_t pid=1; - +#endif try { HTTPD_Connection connection; if(!connection.accept(sock, 5)) continue; switch (HTTPD_Server::mode) { -#if 0 case HTTPD_Server::MULTITHREADED: +#ifdef _MSC_VER + if (!GC_CreateThread(0, 0, connection_thread, new HTTPD_Connection(connection), 0, 0)) + throw Exception("httpd.fork", 0, "thread creation failed"); + connection.sock = -1; + break; +#else pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); @@ -395,7 +411,6 @@ static void httpd_mode() { throw Exception("httpd.fork", 0, "thread creation failed (%d)", result); connection.sock=-1; break; - case HTTPD_Server::PARALLEL: pid=fork(); if(pid<0) @@ -413,8 +428,10 @@ static void httpd_mode() { SAPI::log(*sapiInfo, "%s", e.comment()); } +#ifndef _MSC_VER if(pid==0) // fork child exit(0); +#endif } }