summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/remoteobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/remoteobject.cpp')
-rw-r--r--src/libs/installer/remoteobject.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/libs/installer/remoteobject.cpp b/src/libs/installer/remoteobject.cpp
index 1c521cdf3..b4dd0cbb7 100644
--- a/src/libs/installer/remoteobject.cpp
+++ b/src/libs/installer/remoteobject.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Installer Framework.
@@ -30,6 +30,7 @@
#include "protocol.h"
#include "remoteclient.h"
+#include "globals.h"
#include <QCoreApplication>
#include <QElapsedTimer>
@@ -45,7 +46,6 @@ namespace QInstaller {
RemoteObject::RemoteObject(const QString &wrappedType, QObject *parent)
: QObject(parent)
- , dummy(nullptr)
, m_type(wrappedType)
, m_socket(nullptr)
{
@@ -57,8 +57,22 @@ RemoteObject::~RemoteObject()
{
if (m_socket) {
if (QThread::currentThread() == m_socket->thread()) {
- if (m_type != QLatin1String("RemoteClientPrivate"))
- writeData(QLatin1String(Protocol::Destroy), m_type, dummy, dummy);
+ if ((m_type != QLatin1String("RemoteClientPrivate"))
+ && (m_socket->state() == QLocalSocket::ConnectedState)) {
+ while (m_socket->bytesToWrite()) {
+ // QAbstractSocket::waitForBytesWritten() may fail randomly on Windows, use
+ // an event loop and the bytesWritten() signal instead as the docs suggest.
+ QEventLoop loop;
+ connect(m_socket, &QLocalSocket::bytesWritten, &loop, &QEventLoop::quit);
+ loop.exec();
+ }
+ m_socket->disconnectFromServer();
+ if (!(m_socket->state() == QLocalSocket::UnconnectedState
+ || m_socket->waitForDisconnected())) {
+ qCWarning(lcServer) << "Error while disconnecting from remote server:"
+ << m_socket->error();
+ }
+ }
} else {
Q_ASSERT_X(false, Q_FUNC_INFO, "Socket running in a different Thread than this object.");
}
@@ -107,6 +121,11 @@ bool RemoteObject::connectToServer(const QVariantList &arguments)
sendPacket(m_socket, Protocol::Create, data);
m_socket->flush();
+ while (m_socket->bytesToWrite())
+ m_socket->waitForBytesWritten();
+
+ const QString reply = readData<QString>(QLatin1String(Protocol::Create));
+ Q_ASSERT(reply == QLatin1String(Protocol::DefaultReply));
return true;
}
@@ -120,9 +139,4 @@ bool RemoteObject::isConnectedToServer() const
return false;
}
-void RemoteObject::callRemoteMethod(const QString &name)
-{
- writeData(name, dummy, dummy, dummy);
-}
-
} // namespace QInstaller