--- httpd-2.2.14-v/server/mpm/worker/worker.c 2007-07-18 00:48:25.000000000 +1000 +++ httpd-2.2.14-v/server/mpm/worker/worker.c 2009-11-10 19:51:43.610758253 +1100 @@ -230,6 +230,40 @@ * perform a non-graceful (forced) shutdown of the server. */ static apr_socket_t **worker_sockets; +#ifdef HAVE_PTHREAD_KILL + +#define SOCKET_SIGNAL AP_SIG_GRACEFUL_STOP + +static apr_os_thread_t **worker_os_threads; + +static void worker_socket_shutdown(int sig) +{ + int i; + + for (i = 0; i < ap_threads_per_child; i++) { + if (worker_os_threads[i] && + pthread_equal(*worker_os_threads[i], pthread_self())) { + + if (worker_sockets[i]) { + apr_socket_shutdown(worker_sockets[i], + APR_SHUTDOWN_READWRITE); + } + break; + } + } +} + +static void close_worker_sockets(void) +{ + int i; + + for (i = 0; i < ap_threads_per_child; i++) { + if (worker_os_threads[i]) { + pthread_kill(*worker_os_threads[i], SOCKET_SIGNAL); + } + } +} +#else static void close_worker_sockets(void) { int i; @@ -240,6 +274,7 @@ } } } +#endif static void wakeup_listener(void) { @@ -837,6 +872,9 @@ #ifdef HAVE_PTHREAD_KILL unblock_signal(WORKER_SIGNAL); apr_signal(WORKER_SIGNAL, dummy_signal_handler); + + unblock_signal(SOCKET_SIGNAL); + apr_signal(SOCKET_SIGNAL, worker_socket_shutdown); #endif while (!workers_may_exit) { @@ -977,6 +1015,10 @@ worker_sockets = apr_pcalloc(pchild, ap_threads_per_child * sizeof(apr_socket_t *)); +#ifdef HAVE_PTHREAD_KILL + worker_os_threads = apr_pcalloc(pchild, ap_threads_per_child + * sizeof(*worker_os_threads)); +#endif loops = prev_threads_created = 0; while (1) { @@ -1012,6 +1054,9 @@ /* let the parent decide how bad this really is */ clean_child_exit(APEXIT_CHILDSICK); } +#ifdef HAVE_PTHREAD_KILL + apr_os_thread_get(&worker_os_threads[i], threads[i]); +#endif threads_created++; } /* Start the listener only when there are workers available */