From 0c458ec8c96d15f96947f1fe401654a903152a72 Mon Sep 17 00:00:00 2001 From: Nils Jeisecke Date: Mon, 31 May 2021 15:23:18 +0200 Subject: Add simple acknowledge protocol to ensure the server has received all data The server now acknowledges every received message by sending a \r. By waiting for the acknowledgement, clients should no longer terminate too early, causing bytes getting lost in Qt's internal socket handling. Message handling in the server is simplified because we can now rely on the readyRead signal being raised for every frame. This should finally solve #125 and #121. What remains is to correctly handle data sent using SingleApplication::sendMessage. --- singleapplication.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'singleapplication.cpp') diff --git a/singleapplication.cpp b/singleapplication.cpp index 7e153a0..09e264e 100644 --- a/singleapplication.cpp +++ b/singleapplication.cpp @@ -248,10 +248,7 @@ bool SingleApplication::sendMessage( const QByteArray &message, int timeout ) if( ! d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect ) ) return false; - d->socket->write( message ); - bool dataWritten = d->socket->waitForBytesWritten( timeout ); - d->socket->flush(); - return dataWritten; + return d->writeConfirmedMessage( timeout, message ); } /** -- cgit v1.2.1