From: serassio <> Date: Sun, 28 Aug 2005 01:53:42 +0000 (+0000) Subject: Merge of latest Windows specific updates from nt-3_0 branch: X-Git-Tag: SQUID_3_0_PRE4~665 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11871e3c4a47ac4609717720ee65ff13b4f00b3a;p=thirdparty%2Fsquid.git Merge of latest Windows specific updates from nt-3_0 branch: - Added Winsocks initialization on native Windows --- diff --git a/src/win32.cc b/src/win32.cc index 1f02fab49c..78f7d99182 100644 --- a/src/win32.cc +++ b/src/win32.cc @@ -1,6 +1,6 @@ /* - * $Id: win32.cc,v 1.14 2005/08/27 19:36:36 serassio Exp $ + * $Id: win32.cc,v 1.15 2005/08/27 19:53:42 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -42,6 +42,9 @@ #include "squid_windows.h" #ifdef _SQUID_MSWIN_ +#ifndef _MSWSOCK_ +#include +#endif #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ #include #endif @@ -61,8 +64,11 @@ extern "C" void WINAPI SquidMain(DWORD, char **); #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ void Squid_Win32InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t); #endif +static int Win32SockInit(void); +static void Win32SockCleanup(void); void WIN32_ExceptionHandlerCleanup(void); static LPTOP_LEVEL_EXCEPTION_FILTER Win32_Old_ExceptionHandler = NULL; +static int s_iInitCount = 0; #endif static int Squid_Aborting = 0; @@ -385,6 +391,9 @@ WIN32_Abort(int sig) void WIN32_Exit() { +#ifdef _SQUID_MSWIN_ + Win32SockCleanup(); +#endif #if USE_WIN32_SERVICE if (WIN32_run_mode == _WIN_SQUID_RUN_MODE_SERVICE) { @@ -509,9 +518,13 @@ WIN32_Subsystem_Init() svcStatus.dwCheckPoint = 0; svcStatus.dwWaitHint = 10000; SetServiceStatus(svcHandle, &svcStatus); - } +#endif +#ifdef _SQUID_MSWIN_ + if (Win32SockInit() < 0) + return 1; + #endif return 0; @@ -890,6 +903,65 @@ int main(int argc, char **argv) #endif /* USE_WIN32_SERVICE */ #if defined(_SQUID_MSWIN_) +static int Win32SockInit(void) +{ + int iVersionRequested; + WSADATA wsaData; + int err, opt; + int optlen = sizeof(opt); + + 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) != 2 || + HIBYTE(wsaData.wVersion) != 0) { + s_iInitCount = -2; + WSACleanup(); + return (s_iInitCount); + } + + if (WIN32_OS_version !=_WIN_OS_WINNT) { + if (::getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&opt, &optlen)) { + s_iInitCount = -3; + WSACleanup(); + return (s_iInitCount); + } else { + opt = opt | SO_SYNCHRONOUS_NONALERT; + + if (::setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *) &opt, optlen)) { + s_iInitCount = -3; + WSACleanup(); + return (s_iInitCount); + } + } + } + + WIN32_Socks_initialized = 1; + s_iInitCount++; + return (s_iInitCount); +} + +static void Win32SockCleanup(void) +{ + if (--s_iInitCount == 0) + WSACleanup(); + + return; +} + void Squid_Win32InvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) { return;