Skip to content

Commit 02991f7

Browse files
committed
Revert "move winsock specific stuff into dllmain"
This reverts commit d94c2c7. WSA functions are documented explicitly as unsafe for dllmain
1 parent d94c2c7 commit 02991f7

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

main/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,10 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
20562056
char *php_os, *php_os_family;
20572057
zend_module_entry *module;
20582058

2059+
#ifdef PHP_WIN32
2060+
WORD wVersionRequested = MAKEWORD(2, 0);
2061+
WSADATA wsaData;
2062+
#endif
20592063
#ifdef PHP_WIN32
20602064
php_os = "WINNT";
20612065

@@ -2142,6 +2146,14 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
21422146
tzset();
21432147
#endif
21442148

2149+
#ifdef PHP_WIN32
2150+
/* start up winsock services */
2151+
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
2152+
php_printf("\nwinsock.dll unusable. %d\n", WSAGetLastError());
2153+
return FAILURE;
2154+
}
2155+
#endif
2156+
21452157
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
21462158

21472159
/* Register constants */
@@ -2404,6 +2416,11 @@ void php_module_shutdown(void)
24042416

24052417
zend_shutdown();
24062418

2419+
#ifdef PHP_WIN32
2420+
/*close winsock */
2421+
WSACleanup();
2422+
#endif
2423+
24072424
/* Destroys filter & transport registries too */
24082425
php_shutdown_stream_wrappers(module_number);
24092426

win32/dllmain.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
4040
switch (reason)
4141
{
4242
case DLL_PROCESS_ATTACH:
43-
WORD wVersionRequested = MAKEWORD(2, 0);
44-
WSADATA wsaData;
45-
4643
/*
4744
* We do not need to check the return value of php_win32_init_gettimeofday()
4845
* because the symbol bare minimum symbol we need is always available on our
@@ -62,18 +59,12 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
6259
fprintf(stderr, "ioutil initialization failed");
6360
return ret;
6461
}
65-
66-
ret = ret && (0 == WSAStartup(wVersionRequested, &wsaData));
67-
if (!ret) {
68-
fprintf(stderr, "winsock initialization failed %d", WSAGetLastError());
69-
return ret;
70-
}
7162
break;
63+
#if 0 /* prepared */
7264
case DLL_PROCESS_DETACH:
73-
WSACleanup();
65+
/* pass */
7466
break;
7567

76-
#if 0 /* prepared */
7768
case DLL_THREAD_ATTACH:
7869
/* pass */
7970
break;

0 commit comments

Comments
 (0)