httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Costello <timcoste...@ozemail.com.au>
Subject [PATCH] Win32 - Cleanup winsock initialization
Date Thu, 01 Jan 1970 00:00:00 GMT
Hi again,

Attached inline is a patch to remove redundant calls to WSAStartup/Cleanup - the
windows sockets initialization functions. They used to be called from http_main.c
(I think) in 1.3, in AMCSocketInitialize and AMCSocketCleanup. They still remain 
in the winnt mpm, but are now also called from APR. The only problem is that 
WSAStartup is called every time a pool is created - it only needs to be called 
once per process. 

The patch removes AMCSocketInitialize/Cleanup, and all calls to them from 
winnt.c. It also moves the WSAStartup code from ap_create_pool to 
ap_initialize, and the WSACleanup call from clean_cont (which should disappear
soon anyway?) to ap_terminate. It does not change the return codes to anything
sensible (still APR_EEXIST). 

I should probably mention that after this patch, the Unix and Win32 code for 
ap_create_pool (in start.c) is identical. 

I made this patch assuming that it would be better to just initialize APR and
not have to worry about winsock separately, because [clients of] the APR socket
functions depend on winsock having been initialized anyway. If people disagree 
with this then they probably disagree with the patch.

Tim

===== PATCH FOLLOWS =====

--- /srclib/repos/apache/2.0/src/src/lib/apr/misc/win32/start.c	Sat Apr 22 16:16:37 2000
+++ src/lib/apr/misc/win32/start.c	Thu Apr 27 15:39:44 2000
@@ -64,16 +64,12 @@
 
 ap_status_t clean_cont(void *data)
 {
-    WSACleanup();
     return APR_SUCCESS;
 }
     
 
 ap_status_t ap_create_pool(ap_pool_t **newcont, ap_pool_t *cont)
 {
-    int iVersionRequested;
-    WSADATA wsaData;
-    int err;
     ap_pool_t *new;
 
     if (cont) {
@@ -90,17 +86,6 @@
     new->prog_data = NULL;
     new->apr_abort = NULL;
 
-    iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
-    err = WSAStartup((WORD) iVersionRequested, &wsaData);
-    if (err) {
-        return APR_EEXIST;
-    }
-    if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
-        HIBYTE(wsaData.wVersion) != WSALowByte) {
-        WSACleanup();
-        return APR_EEXIST;
-    }
-
     *newcont = new;
     return APR_SUCCESS;
 }
@@ -249,6 +234,9 @@
 ap_status_t ap_initialize(void)
 {
     ap_status_t status;
+    int iVersionRequested;
+    WSADATA wsaData;
+    int err;
 #if 0
     unsigned tid;
 
@@ -260,11 +248,24 @@
         sleep(1);
     }
 #endif
+
+    iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
+    err = WSAStartup((WORD) iVersionRequested, &wsaData);
+    if (err) {
+        return APR_EEXIST;
+    }
+    if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
+        HIBYTE(wsaData.wVersion) != WSALowByte) {
+        WSACleanup();
+        return APR_EEXIST;
+    }
+
     status = ap_init_alloc();
     return status;
 }
 
 void ap_terminate(void)
 {
+    WSACleanup();
     ap_term_alloc();
 }
--- /srclib/repos/apache/2.0/src/src/modules/mpm/winnt/winnt.c	Wed Apr 26 10:36:49 2000
+++ src/modules/mpm/winnt/winnt.c	Thu Apr 27 15:42:35 2000
@@ -327,45 +327,6 @@
 /*
  * Routines that deal with sockets, some are WIN32 specific...
  */
-static int s_iInitCount = 0;
-static int AMCSocketInitialize(void)
-{
-    int iVersionRequested;
-    WSADATA wsaData;
-    int err;
-
-    if (s_iInitCount > 0) {
-	s_iInitCount++;
-	return (0);
-    }
-    else if (s_iInitCount < 0)
-	return (s_iInitCount);
-
-    /* s_iInitCount == 0. Do the initailization */
-    iVersionRequested = MAKEWORD(2, 0);
-    err = WSAStartup((WORD) iVersionRequested, &wsaData);
-    if (err) {
-	s_iInitCount = -1;
-	return (s_iInitCount);
-    }
-    if (LOBYTE(wsaData.wVersion) != 1 ||
-	HIBYTE(wsaData.wVersion) != 1) {
-	s_iInitCount = -2;
-	WSACleanup();
-	return (s_iInitCount);
-    }
-
-    s_iInitCount++;
-    return (s_iInitCount);
-
-}
-static void AMCSocketCleanup(void)
-{
-    if (--s_iInitCount == 0)
-	WSACleanup();
-    return;
-}
-
 static void sock_disable_nagle(int s) 
 {
     /* The Nagle algorithm says that we should delay sending partial
@@ -1744,8 +1705,6 @@
             ap_log_pid(pconf, ap_pid_fname);
             service_set_status(SERVICE_START_PENDING);
 
-            AMCSocketInitialize();
-        
             /* Create shutdown event, apPID_shutdown, where PID is the parent 
              * Apache process ID. Shutdown is signaled by 'apache -k shutdown'.
              */
@@ -1791,9 +1750,7 @@
         /* Running as Child process or in one_process (debug) mode */
         ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
                      "Child %d: Child process is running", my_pid);
-        AMCSocketInitialize();
         child_main();
-        AMCSocketCleanup();
         ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, server_conf,
                      "Child %d: Child process is exiting", my_pid);        
 
@@ -1815,7 +1772,6 @@
 
             CloseHandle(restart_event);
             CloseHandle(shutdown_event);
-            AMCSocketCleanup();
 
             service_set_status(SERVICE_STOPPED);

===== END OF PATCH =====
This message was sent through MyMail http://www.mymail.com.au



Mime
View raw message