From 25a7b609822f6e8ab9ef6a7850f60c33a8d996f3 Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Mon, 31 May 2021 16:14:39 +0200 Subject: Ensure data sent via SingleApplication::sendMessage is received completely Whilst the initial "connect" message is framed with a length header, this was missing for the user data. Thus there was no guarantee that the message frame was really received completely on emitting the "receivedMessage" signal. This change splits the previous "StageConnected" state into "StageConnectedHeader" and "StageConnectedBody" and does some refactoring to allow using the same write and read functions as the "init" messages. --- singleapplication_p.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'singleapplication_p.h') diff --git a/singleapplication_p.h b/singleapplication_p.h index 0777c33..58507cf 100644 --- a/singleapplication_p.h +++ b/singleapplication_p.h @@ -61,9 +61,10 @@ public: Reconnect = 3 }; enum ConnectionStage : quint8 { - StageHeader = 0, - StageBody = 1, - StageConnected = 2, + StageInitHeader = 0, + StageInitBody = 1, + StageConnectedHeader = 2, + StageConnectedBody = 3, }; Q_DECLARE_PUBLIC(SingleApplication) @@ -79,10 +80,12 @@ public: quint16 blockChecksum() const; qint64 primaryPid() const; QString primaryUser() const; - void readInitMessageHeader(QLocalSocket *socket); + bool isFrameComplete(QLocalSocket *sock); + void readMessageHeader(QLocalSocket *socket, ConnectionStage nextStage); void readInitMessageBody(QLocalSocket *socket); - bool writeConfirmedMessage(int msecs, const QByteArray &msg); void writeAck(QLocalSocket *sock); + bool writeConfirmedFrame(int msecs, const QByteArray &msg); + bool writeConfirmedMessage(int msecs, const QByteArray &msg); static void randomSleep(); void addAppData(const QString &data); QStringList appData() const; -- cgit v1.2.1