"Stop bitcoin server.");
#ifndef QT_GUI
// Shutdown will take long enough that the response should get back
- CreateThread(Shutdown, NULL);
+ // NOTE: This should actually work with Bitcoin-Qt too now, but 0.5.0 didn't allow it
+ StartShutdown();
return "bitcoin server stopping";
#else
throw runtime_error("NYI: cannot shut down GUI with RPC command");
// 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:
- CreateThread(Shutdown, NULL);
+ StartShutdown();
return "wallet encrypted; bitcoin server stopping, restart to run with encrypted wallet";
}
printf("ThreadRPCServer exiting\n");
}
-#ifdef QT_GUI
-extern bool HACK_SHUTDOWN;
-#endif
-
void ThreadRPCServer2(void* parg)
{
printf("ThreadRPCServer started\n");
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()),
_("Error"), wxOK | wxMODAL);
#ifndef QT_GUI
- CreateThread(Shutdown, NULL);
+ StartShutdown();
#endif
return;
}
}
catch(boost::system::system_error &e)
{
- HACK_SHUTDOWN = true;
ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()),
_("Error"), wxOK | wxMODAL);
+ StartShutdown();
return;
}
#endif
#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)
+ 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;
extern CWallet* pwalletMain;
+void StartShutdown();
void Shutdown(void* parg);
bool AppInit(int argc, char* argv[]);
bool AppInit2(int argc, char* argv[]);
strMiscWarning = strMessage;
printf("*** %s\n", strMessage.c_str());
ThreadSafeMessageBox(strMessage, "Bitcoin", wxOK | wxICON_EXCLAMATION);
- CreateThread(Shutdown, NULL);
+ StartShutdown();
return false;
}
return true;
vnThreadsRunning[2]--;
Sleep(100);
if (fRequestShutdown)
- Shutdown(NULL);
+ StartShutdown();
vnThreadsRunning[2]++;
if (fShutdown)
return;
}
}
+void QueueShutdown()
+{
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
+}
+
/*
Translate string to current locale using Qt.
*/
setNumBlocks(clientModel->getNumBlocks());
}
-bool HACK_SHUTDOWN = false;
-
void BitcoinGUI::error(const QString &title, const QString &message, bool modal)
{
// Report errors from network/worker thread
if (modal)
{
QMessageBox::critical(this, title, message, QMessageBox::Ok, QMessageBox::Ok);
- if (HACK_SHUTDOWN)
- QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
} else {
notificator->notify(Notificator::Critical, title, message);
}
extern void CalledSetStatusBar(const std::string& strText, int nField);
extern void UIThreadCall(boost::function0<void> fn);
extern void MainFrameRepaint();
+extern void QueueShutdown();
extern void InitMessage(const std::string &message);
extern std::string _(const char* psz);
CWallet* pwalletMain;
-void Shutdown(void* parg)
+void StartShutdown()
{
exit(0);
}