diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2012-04-05 20:36:27 +0200 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2012-04-11 15:54:30 -0400 |
commit | 1f56046fd529c0ef9e35d26d68995c497751c54f (patch) | |
tree | 0a7160af5dfb7d7a8f53c804af79f8203bfc95a5 /src | |
parent | 527b512cf754bc7846852f3a4a61d8b364c5abc3 (diff) | |
download | bitcoin-1f56046fd529c0ef9e35d26d68995c497751c54f.tar.xz |
Show error message instead of exception crash when unable to bind RPC port
Fixes issue #875
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoinrpc.cpp | 22 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index a4a1fd4d6b..ac20ae8610 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2161,6 +2161,10 @@ void ThreadRPCServer(void* parg) printf("ThreadRPCServer exiting\n"); } +#ifdef QT_GUI +extern bool HACK_SHUTDOWN; +#endif + void ThreadRPCServer2(void* parg) { printf("ThreadRPCServer started\n"); @@ -2196,9 +2200,27 @@ void ThreadRPCServer2(void* parg) asio::io_service io_service; ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", 8332)); +#ifndef QT_GUI ip::tcp::acceptor acceptor(io_service, endpoint); acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); +#else + ip::tcp::acceptor acceptor(io_service); + try + { + acceptor.open(endpoint.protocol()); + acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); + acceptor.bind(endpoint); + acceptor.listen(socket_base::max_connections); + } + catch(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); + return; + } +#endif #ifdef USE_SSL ssl::context context(io_service, ssl::context::sslv23); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 0111ebbc9d..3433c6a183 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -516,12 +516,16 @@ void BitcoinGUI::refreshStatusBar() 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); } |