From: jongfoster Date: Sun, 15 Jul 2001 19:43:49 +0000 (+0000) Subject: Supports POSIX threads. X-Git-Tag: v_2_9_9~248 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=e4a3a7d25cbbda16e284f0b790af122cfa4bd568 Supports POSIX threads. Also removed some unused #includes. --- diff --git a/jcc.c b/jcc.c index 517d9022..78ac93e8 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.23 2001/07/02 02:28:25 iwanttokeepanon Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.24 2001/07/13 14:00:40 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,21 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.23 2001/07/02 02:28:25 iwanttokeepanon Ex * * Revisions : * $Log: jcc.c,v $ + * Revision 1.24 2001/07/13 14:00:40 oes + * - Generic content modification scheme: + * Each feature has its own applicability flag that is set + * from csp->action->flags. + * Replaced the "filtering" int flag , by a function pointer + * "content_filter" to the function that will do the content + * modification. If it is != NULL, the document will be buffered + * and processed through *content_filter, which must set + * csp->content_length and return a modified copy of the body + * or return NULL (on failiure). + * - Changed csp->is_text to the more generic bitmap csp->content_type + * which can currently take the valued CT_TEXT or CT_GIF + * - Reformatting etc + * - Removed all #ifdef PCRS + * * Revision 1.23 2001/07/02 02:28:25 iwanttokeepanon * Added "#ifdef ACL_FILES" conditional compilation to line 1291 to exclude * the `block_acl' call. This prevents a compilation error when the user @@ -225,15 +240,15 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.23 2001/07/02 02:28:25 iwanttokeepanon Ex #include #include -#ifdef _WIN32 +#ifdef FEATURE_PTHREAD +#include +#endif /* def FEATURE_PTHREAD */ -# include -# include -# include -# include -# ifdef TOGGLE -# include -# endif /* def TOGGLE */ +#ifdef _WIN32 +# ifndef FEATURE_PTHREAD +# include +# include +# endif /* ndef FEATURE_PTHREAD */ # include "win32.h" # ifndef _WIN_CONSOLE @@ -1229,12 +1244,12 @@ static void listen_loop(void) while (FOREVER) { -#if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) +#if !defined(FEATURE_PTHREAD) && !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) while (waitpid(-1, NULL, WNOHANG) > 0) { /* zombie children */ } -#endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */ +#endif /* !defined(FEATURE_PTHREAD) && !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */ sweep(); if ( NULL == (csp = (struct client_state *) zalloc(sizeof(*csp))) ) @@ -1338,6 +1353,20 @@ static void listen_loop(void) /* this is a switch () statment in the C preprocessor - ugh */ #undef SELECTED_ONE_OPTION +/* Use Pthreads in preference to native code */ +#if defined(FEATURE_PTHREAD) && !defined(SELECTED_ONE_OPTION) +#define SELECTED_ONE_OPTION + { + pthread_t the_thread; + pthread_attr_t attrs; + + pthread_attr_init(&attrs); + child_id = (pthread_create(&the_thread, &attrs, + (void*)serve, csp) ? -1 : 0); + pthread_attr_destroy(&attrs); + } +#endif + #if defined(_WIN32) && !defined(_CYGWIN) && !defined(SELECTED_ONE_OPTION) #define SELECTED_ONE_OPTION child_id = _beginthread( @@ -1383,27 +1412,7 @@ static void listen_loop(void) #if !defined(SELECTED_ONE_OPTION) child_id = fork(); -#endif - -#undef SELECTED_ONE_OPTION -/* end of cpp switch () */ - - if (child_id < 0) /* failed */ - { - char buf[BUFFER_SIZE]; - - log_error(LOG_LEVEL_ERROR, "can't fork: %E"); - - sprintf(buf , "JunkBuster: can't fork: errno = %d", errno); - write_socket(csp->cfd, buf, strlen(buf)); - close_socket(csp->cfd); - csp->active = 0; - sleep(5); - continue; - } - -#if !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) /* This block is only needed when using fork(). * When using threads, the server thread was * created and run by the call to _beginthread(). @@ -1414,7 +1423,7 @@ static void listen_loop(void) _exit(0); } - else /* parent */ + else if (child_id > 0) /* parent */ { /* in a fork()'d environment, the parent's * copy of the client socket and the CSP @@ -1427,7 +1436,25 @@ static void listen_loop(void) close_socket(csp->cfd); csp->active = 0; } -#endif /* !defined(_WIN32) && !defined(__BEOS__) && !defined(AMIGA) */ +#endif + +#undef SELECTED_ONE_OPTION +/* end of cpp switch () */ + + if (child_id < 0) /* failed */ + { + char buf[BUFFER_SIZE]; + + log_error(LOG_LEVEL_ERROR, "can't fork: %E"); + + sprintf(buf , "JunkBuster: can't fork: errno = %d", errno); + + write_socket(csp->cfd, buf, strlen(buf)); + close_socket(csp->cfd); + csp->active = 0; + sleep(5); + continue; + } } else {