summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/remoteobject.h
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2015-02-16 10:20:07 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-02-20 10:22:31 +0000
commitdf667f7560f2625d7278935a18bf12b47f76d4d3 (patch)
tree968b3216de517fa363f5d22166a0de462d90e374 /src/libs/installer/remoteobject.h
parentd6bca86cad962a0078c2a8111133cff123f1ba0a (diff)
Fix handling of incomplete messages in client/server communication
Do not assume that the socket always contains enough data. Instead, prefix every 'packet' with its size, and back off until the full packet is available. The actual encoding/decoding is done in Protocol::sendPacket, Protocol::receivePacket. To be able to use the methods everywhere, replies are now prefixed by a Protocol::Reply command. Change-Id: I75a89605b2cc3fe2f2f841d8e3159fc8aea65d77 Reviewed-by: Karsten Heimrich <karsten.heimrich@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/remoteobject.h')
-rw-r--r--src/libs/installer/remoteobject.h29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/libs/installer/remoteobject.h b/src/libs/installer/remoteobject.h
index d756b1f3d..979d8fafd 100644
--- a/src/libs/installer/remoteobject.h
+++ b/src/libs/installer/remoteobject.h
@@ -37,7 +37,9 @@
#include "errors.h"
#include "installer_global.h"
+#include "protocol.h"
+#include <QCoreApplication>
#include <QDataStream>
#include <QObject>
#include <QLocalSocket>
@@ -90,20 +92,29 @@ public:
T callRemoteMethod(const QString &name, const T1 &arg, const T2 &arg2, const T3 &arg3) const
{
writeData(name, arg, arg2, arg3);
- if (!m_socket->bytesAvailable())
- m_socket->waitForReadyRead(-1);
- quint32 size; m_stream >> size;
- while (m_socket->bytesAvailable() < size) {
+ QByteArray command;
+ QByteArray data;
+ while (!receivePacket(m_socket, &command, &data)) {
if (!m_socket->waitForReadyRead(30000)) {
throw Error(tr("Could not read all data after sending command: %1. "
- "Bytes expected: %2, Bytes received: %3. Error: %4").arg(name).arg(size)
+ "Bytes expected: %2, Bytes received: %3. Error: %4").arg(name).arg(0)
.arg(m_socket->bytesAvailable()).arg(m_socket->errorString()));
}
+#if defined Q_OS_WIN && QT_VERSION < QT_VERSION_CHECK(5,5,0)
+ // work around QTBUG-16688
+ QCoreApplication::processEvents();
+#endif
}
+ Q_ASSERT(command == Protocol::Reply);
+
+ QDataStream stream(&data, QIODevice::ReadOnly);
+
T result;
- m_stream >> result;
+ stream >> result;
+ Q_ASSERT(stream.status() == QDataStream::Ok);
+ Q_ASSERT(stream.atEnd());
return result;
}
@@ -143,16 +154,12 @@ private:
if (isValueType(arg3))
out << arg3;
- m_stream << name;
- m_stream << quint32(data.size());
- m_stream << data;
- m_socket->waitForBytesWritten(-1);
+ sendPacket(m_socket, name.toLatin1(), data);
}
private:
QString m_type;
QLocalSocket *m_socket;
- mutable QDataStream m_stream;
};
} // namespace QInstaller