Skip to content

Commit 26c9b83

Browse files
committed
Move windows socket init to utility function
1 parent 4be0b08 commit 26c9b83

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

src/bitcoin-cli.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ int CommandLineRPC(int argc, char *argv[])
301301
int main(int argc, char* argv[])
302302
{
303303
SetupEnvironment();
304+
if (!SetupNetworking()) {
305+
fprintf(stderr, "Error: Initializing networking failed\n");
306+
exit(1);
307+
}
304308

305309
try {
306310
if(!AppInitRPC(argc, argv))

src/init.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
658658
typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD);
659659
PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy");
660660
if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE);
661-
662-
// Initialize Windows Sockets
663-
WSADATA wsadata;
664-
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
665-
if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
666-
{
667-
return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret));
668-
}
669661
#endif
670-
#ifndef WIN32
671662

663+
if (!SetupNetworking())
664+
return InitError("Error: Initializing networking failed");
665+
666+
#ifndef WIN32
672667
if (GetBoolArg("-sysperms", false)) {
673668
#ifdef ENABLE_WALLET
674669
if (!GetBoolArg("-disablewallet", false))

src/util.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,18 @@ void SetupEnvironment()
794794
boost::filesystem::path::imbue(loc);
795795
}
796796

797+
bool SetupNetworking()
798+
{
799+
#ifdef WIN32
800+
// Initialize Windows Sockets
801+
WSADATA wsadata;
802+
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
803+
if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
804+
return false;
805+
#endif
806+
return true;
807+
}
808+
797809
void SetThreadPriority(int nPriority)
798810
{
799811
#ifdef WIN32

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ inline std::string _(const char* psz)
5959
}
6060

6161
void SetupEnvironment();
62+
bool SetupNetworking();
6263

6364
/** Return true if log accepts specified category */
6465
bool LogAcceptCategory(const char* category);

0 commit comments

Comments
 (0)