From 896899e0d66e25f6549a92749d237c8a87b12f08 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sun, 17 Jun 2012 16:21:09 +0200 Subject: [PATCH] *Always* send a shutdown signal to enable custom shutdown actions NOTE: This is required to be sure that we can properly shut down the RPC thread. Signed-off-by: Giel van Schijndel --- src/bitcoinrpc.cpp | 3 +-- src/init.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 01142ab7c..a35d33e14 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2884,8 +2884,7 @@ void ThreadRPCServer2(void* parg) } vnThreadsRunning[THREAD_RPCLISTENER]--; - while (!fShutdown) - io_service.run_one(); + io_service.run(); vnThreadsRunning[THREAD_RPCLISTENER]++; // Terminate all outstanding accept-requests diff --git a/src/init.cpp b/src/init.cpp index 08b594f56..4e0947a16 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -9,6 +9,7 @@ #include "init.h" #include "util.h" #include "ui_interface.h" +#include #include #include #include @@ -40,13 +41,8 @@ void ExitTimeout(void* parg) void StartShutdown() { -#ifdef QT_GUI // ensure we leave the Qt main loop for a clean GUI exit (Shutdown() is called in bitcoin.cpp afterwards) uiInterface.QueueShutdown(); -#else - // Without UI, Shutdown() can simply be started in a new thread - CreateThread(Shutdown, NULL); -#endif } void Shutdown(void* parg) @@ -154,6 +150,11 @@ bool AppInit(int argc, char* argv[]) exit(ret); } + // Create the shutdown thread when receiving a shutdown signal + boost::signals2::scoped_connection do_stop( + uiInterface.QueueShutdown.connect(boost::bind( + &CreateThread, &Shutdown, static_cast(0), false))); + fRet = AppInit2(); } catch (std::exception& e) {