diff options
| author | Jaquee <jaquee.monero@gmail.com> | 2017-02-25 20:25:16 +0100 |
|---|---|---|
| committer | Jaquee <jaquee.monero@gmail.com> | 2017-02-25 20:25:16 +0100 |
| commit | 80210376f3fb80116f4592dd206247bf82fd7edc (patch) | |
| tree | a7b5305b61d1fbbedd3eaef9988080f52322d557 /src/daemon/DaemonManager.cpp | |
| parent | df60c8190bf2da1ffca6660392158fe8ee520cd6 (diff) | |
| download | monzero-gui-80210376f3fb80116f4592dd206247bf82fd7edc.tar.gz monzero-gui-80210376f3fb80116f4592dd206247bf82fd7edc.tar.xz monzero-gui-80210376f3fb80116f4592dd206247bf82fd7edc.zip | |
pause refresh while starting daemon + startup timeout
Diffstat (limited to 'src/daemon/DaemonManager.cpp')
| -rw-r--r-- | src/daemon/DaemonManager.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 855058eb..47ad10cf 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -7,6 +7,11 @@ #include <QtConcurrent/QtConcurrent> #include <QApplication> #include <QProcess> +#include <QTime> + +namespace { + static const int DAEMON_START_TIMEOUT_SECONDS = 30; +} DaemonManager * DaemonManager::m_instance = nullptr; QStringList DaemonManager::m_clArgs; @@ -67,8 +72,11 @@ bool DaemonManager::start(const QString &flags, bool testnet) // add state changed listener connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState))); - if (!started) + if (!started) { qDebug() << "Daemon start error: " + m_daemon->errorString(); + emit daemonStartFailure(); + return false; + } // Start start watcher QFuture<bool> future = QtConcurrent::run(this, &DaemonManager::startWatcher, testnet); @@ -77,14 +85,15 @@ bool DaemonManager::start(const QString &flags, bool testnet) this, [this, watcher]() { QFuture<bool> future = watcher->future(); watcher->deleteLater(); - if(future.result()) { + if(future.result()) emit daemonStarted(); - } + else + emit daemonStartFailure(); }); watcher->setFuture(future); - return started; + return true; } bool DaemonManager::stop(bool testnet) @@ -112,12 +121,17 @@ bool DaemonManager::stop(bool testnet) bool DaemonManager::startWatcher(bool testnet) const { // Check if daemon is started every 2 seconds - while(true && !m_app_exit) { + QTime timer; + timer.restart(); + while(true && !m_app_exit && timer.elapsed() / 1000 < DAEMON_START_TIMEOUT_SECONDS ) { QThread::sleep(2); if(!running(testnet)) { qDebug() << "daemon not running. checking again in 2 seconds."; - } else + } else { + qDebug() << "daemon is started. Waiting 5 seconds to let daemon catch up"; + QThread::sleep(5); return true; + } } return false; } |
