Skip to content

Commit d94c2c7

Browse files
committed
move winsock specific stuff into dllmain
1 parent cefa8dd commit d94c2c7

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

main/main.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,10 +2056,6 @@ 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
20632059
#ifdef PHP_WIN32
20642060
php_os = "WINNT";
20652061

@@ -2146,14 +2142,6 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
21462142
tzset();
21472143
#endif
21482144

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-
21572145
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
21582146

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

24172405
zend_shutdown();
24182406

2419-
#ifdef PHP_WIN32
2420-
/*close winsock */
2421-
WSACleanup();
2422-
#endif
2423-
24242407
/* Destroys filter & transport registries too */
24252408
php_shutdown_stream_wrappers(module_number);
24262409

win32/dllmain.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ 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+
4346
/*
4447
* We do not need to check the return value of php_win32_init_gettimeofday()
4548
* 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)
5962
fprintf(stderr, "ioutil initialization failed");
6063
return ret;
6164
}
65+
66+
ret = ret && (0 == WSAStartup(wVersionRequested, &wsaData));
67+
if (!ret) {
68+
fprintf(stderr, "winsock initialization failed %d", WSAGetLastError());
69+
return ret;
70+
}
6271
break;
63-
#if 0 /* prepared */
6472
case DLL_PROCESS_DETACH:
65-
/* pass */
73+
WSACleanup();
6674
break;
6775

76+
#if 0 /* prepared */
6877
case DLL_THREAD_ATTACH:
6978
/* pass */
7079
break;

0 commit comments

Comments
 (0)