summaryrefslogtreecommitdiffstats
path: root/examples/network/blockingfortuneclient/fortunethread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/network/blockingfortuneclient/fortunethread.cpp')
-rw-r--r--examples/network/blockingfortuneclient/fortunethread.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/examples/network/blockingfortuneclient/fortunethread.cpp b/examples/network/blockingfortuneclient/fortunethread.cpp
index b948d504ae..67ac7ebfa5 100644
--- a/examples/network/blockingfortuneclient/fortunethread.cpp
+++ b/examples/network/blockingfortuneclient/fortunethread.cpp
@@ -1,12 +1,22 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
-** You may use this file under the terms of the BSD license as follows:
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
@@ -96,37 +106,27 @@ void FortuneThread::run()
emit error(socket.error(), socket.errorString());
return;
}
-//! [8] //! [9]
-
- while (socket.bytesAvailable() < (int)sizeof(quint16)) {
- if (!socket.waitForReadyRead(Timeout)) {
- emit error(socket.error(), socket.errorString());
- return;
- }
-//! [9] //! [10]
- }
-//! [10] //! [11]
+//! [8] //! [11]
- quint16 blockSize;
QDataStream in(&socket);
in.setVersion(QDataStream::Qt_4_0);
- in >> blockSize;
+ QString fortune;
//! [11] //! [12]
- while (socket.bytesAvailable() < blockSize) {
+ do {
if (!socket.waitForReadyRead(Timeout)) {
emit error(socket.error(), socket.errorString());
return;
}
-//! [12] //! [13]
- }
-//! [13] //! [14]
+
+ in.startTransaction();
+ in >> fortune;
+ } while (!in.commitTransaction());
+//! [12] //! [15]
mutex.lock();
- QString fortune;
- in >> fortune;
emit newFortune(fortune);
-//! [7] //! [14] //! [15]
+//! [7]
cond.wait(&mutex);
serverName = hostName;