Mercurial > hg > bitcoin
changeset 2898:1de8a73c3b99 draft
Show error message instead of exception crash when unable to bind RPC port
Fixes issue #875
author | Wladimir J. van der Laan <laanwj@gmail.com> |
---|---|
date | Thu, 05 Apr 2012 20:36:27 +0200 |
parents | b790b3ffda99 |
children | 790bfe723cf5 |
files | src/bitcoinrpc.cpp src/qt/bitcoingui.cpp |
diffstat | 2 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2161,6 +2161,10 @@ printf("ThreadRPCServer exiting\n"); } +#ifdef QT_GUI +extern bool HACK_SHUTDOWN; +#endif + void ThreadRPCServer2(void* parg) { printf("ThreadRPCServer started\n"); @@ -2196,9 +2200,27 @@ 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);
--- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -516,12 +516,16 @@ 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); }