]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Win32: Port Win32DisableAcceptEx from 2.1
authorBill Stoddard <stoddard@apache.org>
Thu, 29 Jan 2004 03:20:14 +0000 (03:20 +0000)
committerBill Stoddard <stoddard@apache.org>
Thu, 29 Jan 2004 03:20:14 +0000 (03:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@102441 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
server/mpm/winnt/child.c
server/mpm/winnt/mpm_winnt.c
server/mpm/winnt/mpm_winnt.h

diff --git a/CHANGES b/CHANGES
index e7a6f356715c83dd171937112ed808515fee8f41..dda7e01d9f8713c80b5345a56c38f62d254e2fdc 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,11 @@
 Changes with Apache 2.0.49
+  *) Win32: Add Win32DisableAcceptEx directive. This Windows
+     NT/2000/CP directive is useful to work around bugs in some 
+     third party layered service providers like virus scanners, 
+     VPN and firewall products, that do not properly handle 
+     WinSock 2 APIs.  Use this directive if your server is issuing
+     AcceptEx failed messages.
+     [Allan Edwards, Bill Rowe, Bill Stoddard, Jeff Trawick]
 
   *) Make REMOTE_PORT variable available in mod_rewrite.
      PR 25772.  [AndrĂ© Malo]
diff --git a/STATUS b/STATUS
index a9487049030f3ab11fcfd5d573eee64720234cb1..049679fad87e48a964d30eb753a31b11c49ecaed 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                              -*-text-*-
-Last modified at [$Date: 2004/01/28 22:35:54 $]
+Last modified at [$Date: 2004/01/29 03:20:14 $]
 
 Release:
 
@@ -113,15 +113,6 @@ PATCHES TO BACKPORT FROM 2.1
       http://cvs.apache.org/viewcvs.cgi/httpd-2.0/modules/proxy/proxy_http.c?r1=1.176&r2=1.177 
       +1: stoddard, nd
 
-    * Win32: Port Win32DisableAcceptEx directive. This fix enables using
-      Winsock 1.1 accept() call in place of Winsock 2.0 AcceptEx() to work 
-      around bugs in third party layered service providers (e.g. virus
-      scanners) that do not properly handle various Winsock 2 APIs.
-      http://cvs.apache.org/viewcvs.cgi/httpd-2.0/server/mpm/winnt/child.c?r1=1.19&r2=1.20
-      http://cvs.apache.org/viewcvs.cgi/httpd-2.0/server/mpm/winnt/mpm_winnt.c?r1=1.301&r2=1.302
-      http://cvs.apache.org/viewcvs.cgi/httpd-2.0/server/mpm/winnt/mpm_winnt.h?r1=1.42&r2=1.43
-      +1: stoddard, trawick (with subsequent change to messages), ake
-
     * If large file support is enabled, allow any file that is greater than
       AP_MAX_SENDFILE to be split into multiple buckets. This allows Apache
       to send files that are greater than 2gig. Otherwise we run into 
index c230f731b46c61468e973e907f4910940e1db0aa..bf07dfb5dffb63992d5aa117135cb9bce28da729 100644 (file)
@@ -709,11 +709,11 @@ static void worker_main(long thread_num)
         ap_update_child_status_from_indexes(0, thread_num, SERVER_READY, NULL);
 
         /* Grab a connection off the network */
-        if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
-            context = win9x_get_connection(context);
+        if (use_acceptex) {
+            context = winnt_get_connection(context);
         }
         else {
-            context = winnt_get_connection(context);
+            context = win9x_get_connection(context);
         }
         if (!context) {
             /* Time for the thread to exit */
@@ -741,6 +741,16 @@ static void worker_main(long thread_num)
                 context->accept_socket = INVALID_SOCKET;
                 ap_lingering_close(c);
             }
+            else if (!use_acceptex) {
+                /* If the socket is disconnected but we are not using acceptex, 
+                 * we cannot reuse the socket. Disconnected sockets are removed
+                 * from the apr_socket_t struct by apr_sendfile() to prevent the
+                 * socket descriptor from being inadvertently closed by a call 
+                 * to apr_socket_close(), so close it directly.
+                 */
+                closesocket(context->accept_socket);
+                context->accept_socket = INVALID_SOCKET;
+            }
         }
         else {
             /* ap_run_create_connection closes the socket on failure */
@@ -777,7 +787,7 @@ static void cleanup_thread(HANDLE *handles, int *thread_cnt, int thread_to_clean
 static void create_listener_thread()
 {
     int tid;
-    if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+    if (!use_acceptex) {
         _beginthreadex(NULL, 0, (LPTHREAD_START_ROUTINE) win9x_accept,
                        NULL, 0, &tid);
     } else {
@@ -1015,7 +1025,7 @@ void child_main(apr_pool_t *pconf)
     }
 
     /* Shutdown the worker threads */
-    if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
+    if (!use_acceptex) {
         for (i = 0; i < threads_created; i++) {
             add_job(INVALID_SOCKET);
         }
@@ -1073,8 +1083,8 @@ void child_main(apr_pool_t *pconf)
 
     CloseHandle(allowed_globals.jobsemaphore);
     apr_thread_mutex_destroy(allowed_globals.jobmutex);
-    if (osver.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
-       apr_thread_mutex_destroy(qlock);
+    if (use_acceptex) {
+        apr_thread_mutex_destroy(qlock);
         CloseHandle(qwait_event);
     }
 
index 64566614bbc1533ddf1b2fd43827119bee03a40c..4d775a828f18abe7138291da0d6234f8e488873f 100644 (file)
@@ -103,6 +103,7 @@ static DWORD parent_pid;
 DWORD my_pid;
 
 int ap_threads_per_child = 0;
+int use_acceptex = 1;
 static int thread_limit = DEFAULT_THREAD_LIMIT;
 static int first_thread_limit = 0;
 static int changed_limit_at_restart;
@@ -217,6 +218,19 @@ static const char *set_thread_limit (cmd_parms *cmd, void *dummy, const char *ar
     }
     return NULL;
 }
+static const char *set_disable_acceptex(cmd_parms *cmd, void *dummy, char *arg) 
+{
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL) {
+        return err;
+    }
+    if (use_acceptex) {
+        use_acceptex = 0;
+        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, 
+                     "Disabled use of AcceptEx() WinSock2 API");
+    }
+    return NULL;
+}
 
 static const command_rec winnt_cmds[] = {
 LISTEN_COMMANDS,
@@ -224,6 +238,8 @@ AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF,
   "Number of threads each child creates" ),
 AP_INIT_TAKE1("ThreadLimit", set_thread_limit, NULL, RSRC_CONF,
   "Maximum worker threads in a server for this run of Apache"),
+AP_INIT_NO_ARGS("Win32DisableAcceptEx", set_disable_acceptex, NULL, RSRC_CONF,
+  "Disable use of the high performance AcceptEx WinSock2 API to work around buggy VPN or Firewall software"),
 { NULL }
 };
 
index 01a7c0204cb3dd002913a626eca038256e6886aa..0444638a62604591920dba784cd38cff69725b7f 100644 (file)
@@ -100,7 +100,7 @@ void mpm_nt_eventlog_stderr_open(char *display_name, apr_pool_t *p);
 void mpm_nt_eventlog_stderr_flush(void);
 
 /* From winnt.c: */
-
+extern int use_acceptex;
 extern OSVERSIONINFO osver;
 extern void clean_child_exit(int);