Skip to content

Commit

Permalink
Move windows socket init to utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
laanwj authored and str4d committed Mar 23, 2017
1 parent 91295c4 commit 167b623
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ int CommandLineRPC(int argc, char *argv[])
int main(int argc, char* argv[])
{
SetupEnvironment();
if (!SetupNetworking()) {
fprintf(stderr, "Error: Initializing networking failed\n");
exit(1);
}

try {
if(!AppInitRPC(argc, argv))
Expand Down
13 changes: 4 additions & 9 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
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 || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
{
return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret));
}
#endif
#ifndef WIN32

if (!SetupNetworking())
return InitError("Error: Initializing networking failed");

#ifndef WIN32
if (GetBoolArg("-sysperms", false)) {
#ifdef ENABLE_WALLET
if (!GetBoolArg("-disablewallet", false))
Expand Down
12 changes: 12 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,18 @@ void SetupEnvironment()
boost::filesystem::path::imbue(loc);
}

bool SetupNetworking()
{
#ifdef WIN32
// Initialize Windows Sockets
WSADATA wsadata;
int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
return false;
#endif
return true;
}

void SetThreadPriority(int nPriority)
{
#ifdef WIN32
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ inline std::string _(const char* psz)
}

void SetupEnvironment();
bool SetupNetworking();

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

0 comments on commit 167b623

Please sign in to comment.