diff options
author | Samuel Gaist <samuel.gaist@idiap.ch> | 2023-11-29 10:49:30 +0100 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@idiap.ch> | 2023-12-04 22:13:26 +0100 |
commit | fd1405e61b9939e2630c751367413e07fdc76408 (patch) | |
tree | a157000dcb4fb2efbdd67990b3a58de58ed939fa /examples/corelib | |
parent | 8220173b020fd28fdf9635fbd46c9505b9d9442a (diff) |
examples: update local fortune example to use transaction
The local version of the fortune server and clients were not using the
transaction paradigm yet. This patches fixes it and makes the example in
line with the network version.
Pick-to: 6.6 6.5
Change-Id: Ieb68f67e2921f46acd682f81dfa5dc5b040c88f5
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Diffstat (limited to 'examples/corelib')
-rw-r--r-- | examples/corelib/ipc/localfortuneclient/client.cpp | 14 | ||||
-rw-r--r-- | examples/corelib/ipc/localfortuneserver/server.cpp | 3 |
2 files changed, 5 insertions, 12 deletions
diff --git a/examples/corelib/ipc/localfortuneclient/client.cpp b/examples/corelib/ipc/localfortuneclient/client.cpp index 8336728f79..b71409560b 100644 --- a/examples/corelib/ipc/localfortuneclient/client.cpp +++ b/examples/corelib/ipc/localfortuneclient/client.cpp @@ -63,20 +63,14 @@ void Client::requestNewFortune() void Client::readFortune() { - if (blockSize == 0) { - // Relies on the fact that QDataStream serializes a quint32 into - // sizeof(quint32) bytes - if (socket->bytesAvailable() < (int)sizeof(quint32)) - return; - in >> blockSize; - } - - if (socket->bytesAvailable() < blockSize || in.atEnd()) - return; + in.startTransaction(); QString nextFortune; in >> nextFortune; + if (!in.commitTransaction()) + return; + if (nextFortune == currentFortune) { QTimer::singleShot(0, this, &Client::requestNewFortune); return; diff --git a/examples/corelib/ipc/localfortuneserver/server.cpp b/examples/corelib/ipc/localfortuneserver/server.cpp index 77322e03bd..a602a57f72 100644 --- a/examples/corelib/ipc/localfortuneserver/server.cpp +++ b/examples/corelib/ipc/localfortuneserver/server.cpp @@ -103,10 +103,9 @@ void Server::sendFortune() { QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); - out.setVersion(QDataStream::Qt_6_0); + out.setVersion(QDataStream::Qt_6_5); const int fortuneIndex = QRandomGenerator::global()->bounded(0, fortunes.size()); const QString &message = fortunes.at(fortuneIndex); - out << quint32(message.size()); out << message; QLocalSocket *clientConnection = server->nextPendingConnection(); |