Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoind.cpp
Show All 11 Lines | |||||
#include "compat.h" | #include "compat.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "fs.h" | #include "fs.h" | ||||
#include "httprpc.h" | #include "httprpc.h" | ||||
#include "httpserver.h" | #include "httpserver.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "noui.h" | #include "noui.h" | ||||
#include "rpc/server.h" | #include "rpc/server.h" | ||||
#include "scheduler.h" | |||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#if ENABLE_WALLET | #if ENABLE_WALLET | ||||
#include "wallet/init.h" | #include "wallet/init.h" | ||||
#endif | #endif | ||||
#include "walletinitinterface.h" | #include "walletinitinterface.h" | ||||
#include <boost/thread.hpp> | #include <boost/thread.hpp> | ||||
Show All 16 Lines | |||||
* The software is a community-driven open source project, released under the | * The software is a community-driven open source project, released under the | ||||
* MIT license. | * MIT license. | ||||
* | * | ||||
* \section Navigation | * \section Navigation | ||||
* Use the buttons <code>Namespaces</code>, <code>Classes</code> or | * Use the buttons <code>Namespaces</code>, <code>Classes</code> or | ||||
* <code>Files</code> at the top of the page to start navigating the code. | * <code>Files</code> at the top of the page to start navigating the code. | ||||
*/ | */ | ||||
void WaitForShutdown(boost::thread_group *threadGroup) { | void WaitForShutdown() { | ||||
while (!ShutdownRequested()) { | while (!ShutdownRequested()) { | ||||
MilliSleep(200); | MilliSleep(200); | ||||
} | } | ||||
if (threadGroup) { | Interrupt(); | ||||
Interrupt(*threadGroup); | |||||
threadGroup->join_all(); | |||||
} | |||||
} | } | ||||
////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////// | ||||
// | // | ||||
// Start | // Start | ||||
// | // | ||||
bool AppInit(int argc, char *argv[]) { | bool AppInit(int argc, char *argv[]) { | ||||
boost::thread_group threadGroup; | |||||
CScheduler scheduler; | |||||
// FIXME: Ideally, we'd like to build the config here, but that's currently | // FIXME: Ideally, we'd like to build the config here, but that's currently | ||||
// not possible as the whole application has too many global state. However, | // not possible as the whole application has too many global state. However, | ||||
// this is a first step. | // this is a first step. | ||||
auto &config = const_cast<Config &>(GetConfig()); | auto &config = const_cast<Config &>(GetConfig()); | ||||
RPCServer rpcServer; | RPCServer rpcServer; | ||||
HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); | HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); | ||||
bool fRet = false; | bool fRet = false; | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | |||||
#endif // HAVE_DECL_DAEMON | #endif // HAVE_DECL_DAEMON | ||||
} | } | ||||
// Lock data directory after daemonization | // Lock data directory after daemonization | ||||
if (!AppInitLockDataDirectory()) { | if (!AppInitLockDataDirectory()) { | ||||
// If locking the data directory failed, exit immediately | // If locking the data directory failed, exit immediately | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
fRet = AppInitMain(config, httpRPCRequestProcessor, threadGroup, | fRet = AppInitMain(config, httpRPCRequestProcessor); | ||||
scheduler); | |||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
PrintExceptionContinue(&e, "AppInit()"); | PrintExceptionContinue(&e, "AppInit()"); | ||||
} catch (...) { | } catch (...) { | ||||
PrintExceptionContinue(nullptr, "AppInit()"); | PrintExceptionContinue(nullptr, "AppInit()"); | ||||
} | } | ||||
if (!fRet) { | if (!fRet) { | ||||
Interrupt(threadGroup); | Interrupt(); | ||||
// threadGroup.join_all(); was left out intentionally here, because we | |||||
// didn't re-test all of the startup-failure cases to make sure they | |||||
// don't result in a hang due to some | |||||
// thread-blocking-waiting-for-another-thread-during-startup case. | |||||
} else { | } else { | ||||
WaitForShutdown(&threadGroup); | WaitForShutdown(); | ||||
} | } | ||||
Shutdown(); | Shutdown(); | ||||
return fRet; | return fRet; | ||||
} | } | ||||
int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | ||||
SetupEnvironment(); | SetupEnvironment(); | ||||
// Connect bitcoind signal handlers | // Connect bitcoind signal handlers | ||||
noui_connect(); | noui_connect(); | ||||
return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE); | return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE); | ||||
} | } |