diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-02-19 08:54:23 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-03-05 14:57:27 +0000 |
commit | 739fb83870fefbeeb3d92e92670c6cbe65f5c963 (patch) | |
tree | 26a4325ea8c0e222afa111270f88738793ac508f /src/libs/installer/keepaliveobject.cpp | |
parent | a4a19844d2e14003e21352506ba067e11a94de2b (diff) |
Simplify KeepAliveObject implementation
Change-Id: I5c647510a8aa001183c9bf63ac0e1cae5ec32ce9
Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/keepaliveobject.cpp')
-rw-r--r-- | src/libs/installer/keepaliveobject.cpp | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/libs/installer/keepaliveobject.cpp b/src/libs/installer/keepaliveobject.cpp index 514ca5a7a..226181120 100644 --- a/src/libs/installer/keepaliveobject.cpp +++ b/src/libs/installer/keepaliveobject.cpp @@ -35,9 +35,6 @@ #include "keepaliveobject.h" #include "remoteclient.h" -#include <QCoreApplication> -#include <QElapsedTimer> -#include <QHostAddress> #include <QLocalSocket> #include <QTimer> @@ -45,41 +42,27 @@ namespace QInstaller { KeepAliveObject::KeepAliveObject() : m_timer(0) - , m_quit(false) + , m_socket(0) { } void KeepAliveObject::start() { m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimeout())); - m_timer->start(5000); -} + m_socket = new QLocalSocket(this); -void KeepAliveObject::finish() -{ - m_quit = true; -} + connect(m_timer, &QTimer::timeout, [this]() { + if (m_socket->state() != QLocalSocket::UnconnectedState) + return; + m_socket->connectToServer(RemoteClient::instance().socketName()); + }); -void KeepAliveObject::onTimeout() -{ - m_timer->stop(); - { - // Try to connect to the privileged running server. If we succeed the server side - // watchdog gets restarted and the server keeps running for another 30 seconds. - QLocalSocket socket; - socket.connectToServer(RemoteClient::instance().socketName()); + connect(m_socket, &QLocalSocket::connected, [this]() { + m_socket->close(); + }); - QElapsedTimer stopWatch; - stopWatch.start(); - while ((socket.state() == QLocalSocket::ConnectingState) - && (stopWatch.elapsed() < 10000) && (!m_quit)) { - if ((stopWatch.elapsed() % 2500) == 0) - QCoreApplication::processEvents(); - } - } - if (!m_quit) - m_timer->start(5000); + m_timer->setInterval(5000); + m_timer->start(); } } // namespace QInstaller |