diff options
author | Samuel Gaist <samuel.gaist@idiap.ch> | 2023-11-29 10:49:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-16 01:34:21 +0000 |
commit | 1bd40b3e94824491482aa38344746d7a1a9c7063 (patch) | |
tree | 6a4b1b8b39ce1f0f67b4d9cc2a6a531c3b41d726 /examples/corelib/ipc/localfortuneclient | |
parent | 03ac42cd8e453ae46dcb5400ca375035c2e1c3f1 (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.5
Change-Id: Ieb68f67e2921f46acd682f81dfa5dc5b040c88f5
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
(cherry picked from commit fd1405e61b9939e2630c751367413e07fdc76408)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples/corelib/ipc/localfortuneclient')
-rw-r--r-- | examples/corelib/ipc/localfortuneclient/client.cpp | 14 |
1 files changed, 4 insertions, 10 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; |