com php-src: move winsock specific stuff into dllmain: main/main.c win32/dllmain.c

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    d94c2c796a1b032d53b382681f8413cc3d02d2da
Author:    Anatol Belski <[email protected]>         Sat, 11 Feb 2017 16:46:17 +0100
Parents:   cefa8ddcc9acc60b2e464b7eac69ee6f25ff19b9
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=d94c2c796a1b032d53b382681f8413cc3d02d2da

Log:
move winsock specific stuff into dllmain

Changed paths:
  M  main/main.c
  M  win32/dllmain.c


Diff:
diff --git a/main/main.c b/main/main.c
index 9e139ef..daa8235 100644
--- a/main/main.c
+++ b/main/main.c
@@ -2057,10 +2057,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
 	zend_module_entry *module;
 
 #ifdef PHP_WIN32
-	WORD wVersionRequested = MAKEWORD(2, 0);
-	WSADATA wsaData;
-#endif
-#ifdef PHP_WIN32
 	php_os = "WINNT";
 
 	old_invalid_parameter_handler =
@@ -2146,14 +2142,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
 	tzset();
 #endif
 
-#ifdef PHP_WIN32
-	/* start up winsock services */
-	if (WSAStartup(wVersionRequested, &wsaData) != 0) {
-		php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
-		return FAILURE;
-	}
-#endif
-
 	le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
 
 	/* Register constants */
@@ -2416,11 +2404,6 @@ void php_module_shutdown(void)
 
 	zend_shutdown();
 
-#ifdef PHP_WIN32
-	/*close winsock */
-	WSACleanup();
-#endif
-
 	/* Destroys filter & transport registries too */
 	php_shutdown_stream_wrappers(module_number);
 
diff --git a/win32/dllmain.c b/win32/dllmain.c
index 1c34fb1..2e5151d 100644
--- a/win32/dllmain.c
+++ b/win32/dllmain.c
@@ -40,6 +40,9 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
 	switch (reason)
 	{
 		case DLL_PROCESS_ATTACH:
+			WORD wVersionRequested = MAKEWORD(2, 0);
+			WSADATA wsaData;
+
 			/*
 			 * We do not need to check the return value of php_win32_init_gettimeofday()
 			 * because the symbol bare minimum symbol we need is always available on our 
@@ -59,12 +62,18 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
 				fprintf(stderr, "ioutil initialization failed");
 				return ret;
 			}
+
+			ret = ret && (0 == WSAStartup(wVersionRequested, &wsaData));
+			if (!ret) {
+				fprintf(stderr, "winsock initialization failed %d", WSAGetLastError());
+				return ret;
+			}
 			break;
-#if 0 /* prepared */
 		case DLL_PROCESS_DETACH:
-			/* pass */
+			WSACleanup();
 			break;
 
+#if 0 /* prepared */
 		case DLL_THREAD_ATTACH:
 			/* pass */
 			break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.