Browse Source

Move windows socket init to utility function

0.13
Wladimir J. van der Laan 9 years ago
parent
commit
26c9b83677
  1. 4
      src/bitcoin-cli.cpp
  2. 13
      src/init.cpp
  3. 12
      src/util.cpp
  4. 1
      src/util.h

4
src/bitcoin-cli.cpp

@ -301,6 +301,10 @@ int CommandLineRPC(int argc, char *argv[]) @@ -301,6 +301,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))

13
src/init.cpp

@ -658,17 +658,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) @@ -658,17 +658,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))

12
src/util.cpp

@ -794,6 +794,18 @@ void SetupEnvironment() @@ -794,6 +794,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

1
src/util.h

@ -59,6 +59,7 @@ inline std::string _(const char* psz) @@ -59,6 +59,7 @@ inline std::string _(const char* psz)
}
void SetupEnvironment();
bool SetupNetworking();
/** Return true if log accepts specified category */
bool LogAcceptCategory(const char* category);

Loading…
Cancel
Save