diff options
author | kh <karsten.heimrich@theqtcompany.com> | 2014-11-27 14:00:32 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2014-12-02 13:28:52 +0100 |
commit | 2e05d089af226f798cbae3f44ff9d131bf682024 (patch) | |
tree | 27611e626476ecc70a4427a4ab212114cf0db7ed /src/libs/installer | |
parent | 5e4f49fd4edbffc302bd14b972f6ea046230a333 (diff) |
Refine server starting/stopping code.
If we can't connect, the server is most likely not running.
Also send an acknowledgment that we are going to shutdown.
Change-Id: I1a06b0ea5b5bdeb736042ca8b49508b6a4fd90b8
Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs/installer')
-rw-r--r-- | src/libs/installer/remoteclient_p.h | 32 | ||||
-rw-r--r-- | src/libs/installer/remoteserverconnection.cpp | 6 |
2 files changed, 18 insertions, 20 deletions
diff --git a/src/libs/installer/remoteclient_p.h b/src/libs/installer/remoteclient_p.h index fed0576a4..5afc32ff5 100644 --- a/src/libs/installer/remoteclient_p.h +++ b/src/libs/installer/remoteclient_p.h @@ -65,7 +65,6 @@ public: , m_port(Protocol::DefaultPort) , m_startServerAs(Protocol::StartAs::User) , m_serverStarted(false) - , m_serverStarting(false) , m_active(false) , m_key(QLatin1String(Protocol::DefaultAuthorizationKey)) , m_mode(Protocol::Mode::Debug) @@ -86,6 +85,7 @@ public: m_thread.quit(); m_thread.wait(); + maybeStopServer(); } void init(quint16 port, const QString &key, Protocol::Mode mode, Protocol::StartAs startAs) @@ -128,12 +128,13 @@ public: const QMutexLocker ml(&m_mutex); if (m_serverStarted) return; + m_serverStarted = false; - m_serverStarting = true; + bool started = false; if (m_startServerAs == Protocol::StartAs::SuperUser) { - m_serverStarted = AdminAuthorization::execute(0, m_serverCommand, m_serverArguments); + started = AdminAuthorization::execute(0, m_serverCommand, m_serverArguments); - if (!m_serverStarted) { + if (!started) { // something went wrong with authorizing, either user pressed cancel or entered // wrong password const QString fallback = m_serverCommand + QLatin1String(" ") + m_serverArguments @@ -150,23 +151,20 @@ public: QMessageBox::Abort | QMessageBox::Ok, QMessageBox::Ok); if (res == QMessageBox::Ok) - m_serverStarted = true; + started = true; } } else { - m_serverStarted = QInstaller::startDetached(m_serverCommand, m_serverArguments, + started = QInstaller::startDetached(m_serverCommand, m_serverArguments, QCoreApplication::applicationDirPath()); } - if (m_serverStarted) { + if (started) { QElapsedTimer t; t.start(); - // 30 seconds ought to be enough for the app to start - while (m_serverStarting && m_serverStarted && t.elapsed() < 30000) { - if (authorize()) - m_serverStarting = false; - } + // 30 seconds waiting ought to be enough for the app to start + while ((!m_serverStarted) && (t.elapsed() < 30000)) + m_serverStarted = authorize(); } - m_serverStarting = false; } void maybeStopServer() @@ -181,9 +179,9 @@ public: if (!m_serverStarted) return; - if (authorize()) - callRemoteMethod(QString::fromLatin1(Protocol::Shutdown)); - m_serverStarted = false; + if (!authorize()) + return; + m_serverStarted = !callRemoteMethod<bool>(QString::fromLatin1(Protocol::Shutdown)); } private: @@ -191,10 +189,8 @@ private: QMutex m_mutex; QHostAddress m_address; quint16 m_port; - QString m_socket; Protocol::StartAs m_startServerAs; bool m_serverStarted; - bool m_serverStarting; bool m_active; QString m_serverCommand; QStringList m_serverArguments; diff --git a/src/libs/installer/remoteserverconnection.cpp b/src/libs/installer/remoteserverconnection.cpp index fbb51641c..0a142c4be 100644 --- a/src/libs/installer/remoteserverconnection.cpp +++ b/src/libs/installer/remoteserverconnection.cpp @@ -74,15 +74,17 @@ void RemoteServerConnection::run() stream >> command; if (authorized && command == QLatin1String(Protocol::Shutdown)) { - // this is a graceful shutdown - socket.close(); authorized = false; + sendData(stream, true); + socket.flush(); + socket.close(); emit shutdownRequested(); return; } else if (command == QLatin1String(Protocol::Authorize)) { QString key; stream >> key; sendData(stream, (authorized = (key == m_authorizationKey))); + socket.flush(); if (!authorized) socket.close(); } else if (authorized) { |