From c3faff07f5e2e4620601c2ef324b492a31bf7088 Mon Sep 17 00:00:00 2001 From: Wladimir J. van der Laan Date: Sun, 28 Apr 2013 08:51:49 +0200 Subject: [PATCH] move WSAStartup to init WSAStartup should be called before using any other socket functions. BindListenPort is not called if not listening. Closes #2585. --- src/init.cpp | 8 ++++++++ src/net.cpp | 12 ------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 66ad72d..417b342 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -344,6 +344,14 @@ bool AppInit2() typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD); PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE); + + // Initialize Windows Sockets + WSADATA wsadata; + int ret = WSAStartup(MAKEWORD(2,2), &wsadata); + if (ret != NO_ERROR) + { + return InitError(strprintf("Error: TCP/IP socket library failed to start (WSAStartup returned error %d)", ret)); + } #endif #ifndef WIN32 umask(077); diff --git a/src/net.cpp b/src/net.cpp index d409949..26b8174 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1537,18 +1537,6 @@ bool BindListenPort(const CService &addrBind, string& strError) strError = ""; int nOne = 1; -#ifdef WIN32 - // Initialize Windows Sockets - WSADATA wsadata; - int ret = WSAStartup(MAKEWORD(2,2), &wsadata); - if (ret != NO_ERROR) - { - strError = strprintf("Error: TCP/IP socket library failed to start (WSAStartup returned error %d)", ret); - printf("%s\n", strError.c_str()); - return false; - } -#endif - // Create socket for listening for incoming connections #ifdef USE_IPV6 struct sockaddr_storage sockaddr; -- 1.7.1