diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-06-13 23:12:22 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-06-13 23:12:22 -0700 |
commit | 0f10b21719e1b0d9683a142f0a7105e65f095694 (patch) | |
tree | e30dcb8b0da343c8ba9ddaca27b7c2c78b7d865a /src | |
parent | 7a98f19fb6e40e2929abfff6b1f20f13c091d32d (diff) | |
parent | 9247134eaba9a1d0fa74f22de238af1476663005 (diff) |
Merge pull request #1439 from Diapolo/ClientShutdown
re-work Shutdown() function
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 14 | ||||
-rw-r--r-- | src/init.cpp | 14 | ||||
-rw-r--r-- | src/init.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/net.cpp | 2 | ||||
-rw-r--r-- | src/noui.cpp | 7 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 1 |
7 files changed, 25 insertions, 16 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 999c6dda09..8c3a615fd1 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -20,7 +20,7 @@ #include <boost/iostreams/stream.hpp> #include <boost/algorithm/string.hpp> #include <boost/lexical_cast.hpp> -#include <boost/asio/ssl.hpp> +#include <boost/asio/ssl.hpp> #include <boost/filesystem/fstream.hpp> typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream; @@ -436,7 +436,7 @@ Value stop(const Array& params, bool fHelp) "stop\n" "Stop Bitcoin server."); // Shutdown will take long enough that the response should get back - uiInterface.QueueShutdown(); + StartShutdown(); return "Bitcoin server stopping"; } @@ -1148,7 +1148,7 @@ Value sendmany(const Array& params, bool fHelp) CScript scriptPubKey; scriptPubKey.SetDestination(address.Get()); - int64 nAmount = AmountFromValue(s.value_); + int64 nAmount = AmountFromValue(s.value_); totalAmount += nAmount; vecSend.push_back(make_pair(scriptPubKey, nAmount)); @@ -1524,7 +1524,7 @@ Value listtransactions(const Array& params, bool fHelp) if ((int)ret.size() >= (nCount+nFrom)) break; } // ret is newest to oldest - + if (nFrom > (int)ret.size()) nFrom = ret.size(); if ((nFrom + nCount) > (int)ret.size()) @@ -1935,7 +1935,7 @@ Value encryptwallet(const Array& params, bool fHelp) // BDB seems to have a bad habit of writing old data into // slack space in .dat files; that is bad if the old data is // unencrypted private keys. So: - uiInterface.QueueShutdown(); + StartShutdown(); return "wallet encrypted; Bitcoin server stopping, restart to run with encrypted wallet"; } @@ -2682,7 +2682,7 @@ void ThreadRPCServer2(void* parg) GetConfigFile().string().c_str(), EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); - uiInterface.QueueShutdown(); + StartShutdown(); return; } @@ -2703,7 +2703,7 @@ void ThreadRPCServer2(void* parg) { uiInterface.ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()), _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); - uiInterface.QueueShutdown(); + StartShutdown(); return; } diff --git a/src/init.cpp b/src/init.cpp index bf9551e858..08b594f56c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -38,6 +38,17 @@ void ExitTimeout(void* parg) #endif } +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) { static CCriticalSection cs_Shutdown; @@ -66,7 +77,10 @@ void Shutdown(void* parg) Sleep(50); printf("Bitcoin exited\n\n"); fExit = true; +#ifndef QT_GUI + // ensure non UI client get's exited here, but let Bitcoin-Qt reach return 0; in bitcoin.cpp exit(0); +#endif } else { diff --git a/src/init.h b/src/init.h index 6159ededa5..8308ee648b 100644 --- a/src/init.h +++ b/src/init.h @@ -9,6 +9,7 @@ extern CWallet* pwalletMain; +void StartShutdown(); void Shutdown(void* parg); bool AppInit2(); std::string HelpMessage(); diff --git a/src/main.cpp b/src/main.cpp index 50a740d160..fa3eb592a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1875,7 +1875,7 @@ bool CheckDiskSpace(uint64 nAdditionalBytes) strMiscWarning = strMessage; printf("*** %s\n", strMessage.c_str()); uiInterface.ThreadSafeMessageBox(strMessage, "Bitcoin", CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL); - uiInterface.QueueShutdown(); + StartShutdown(); return false; } return true; diff --git a/src/net.cpp b/src/net.cpp index d510709082..804cb0f543 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1658,7 +1658,7 @@ void ThreadMessageHandler2(void* parg) vnThreadsRunning[THREAD_MESSAGEHANDLER]--; Sleep(100); if (fRequestShutdown) - Shutdown(NULL); + StartShutdown(); vnThreadsRunning[THREAD_MESSAGEHANDLER]++; if (fShutdown) return; diff --git a/src/noui.cpp b/src/noui.cpp index 3ba7e729f5..db25f2d285 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -20,16 +20,9 @@ static bool noui_ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCapt return true; } -static void noui_QueueShutdown() -{ - // Without UI, Shutdown can simply be started in a new thread - CreateThread(Shutdown, NULL); -} - void noui_connect() { // Connect bitcoind signal handlers uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); uiInterface.ThreadSafeAskFee.connect(noui_ThreadSafeAskFee); - uiInterface.QueueShutdown.connect(noui_QueueShutdown); } diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 2a2d200394..8c8c73f065 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -290,6 +290,7 @@ int main(int argc, char *argv[]) window.setWalletModel(0); guiref = 0; } + // Shutdown the core and it's threads, but don't exit Bitcoin-Qt here Shutdown(NULL); } else |