diff options
author | Nils Jeisecke <nils.jeisecke@saltation.com> | 2021-05-31 16:14:39 +0200 |
---|---|---|
committer | Nils Jeisecke <nils.jeisecke@saltation.com> | 2021-06-01 04:10:53 +0200 |
commit | 25a7b609822f6e8ab9ef6a7850f60c33a8d996f3 (patch) | |
tree | 49ea9772668632a316eddea0bc7bed11dc3efb9c /singleapplication_p.h | |
parent | Add simple acknowledge protocol to ensure the server has received all data (diff) | |
download | singleapplication-25a7b609822f6e8ab9ef6a7850f60c33a8d996f3.tar.xz |
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.
Diffstat (limited to 'singleapplication_p.h')
-rw-r--r-- | singleapplication_p.h | 13 |
1 files changed, 8 insertions, 5 deletions
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; |