summaryrefslogtreecommitdiffstats
path: root/examples/network/loopback
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-02-21 18:47:01 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-02-21 18:56:22 (GMT)
commit1f049c91f91e069a975a72c1087a279d011535a5 (patch)
treeb6bbf86d38a39ef7da2ec05b809a4d6702e052fa /examples/network/loopback
parent7ce06afb341240b102edcc83b33d0da3d9e7ab5e (diff)
downloadQt-1f049c91f91e069a975a72c1087a279d011535a5.zip
Qt-1f049c91f91e069a975a72c1087a279d011535a5.tar.gz
Qt-1f049c91f91e069a975a72c1087a279d011535a5.tar.bz2
loopback network example: Make use of bytesToWrite()
Reviewed-by: TrustMe
Diffstat (limited to 'examples/network/loopback')
-rw-r--r--examples/network/loopback/dialog.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp
index 27cff31..b504e36 100644
--- a/examples/network/loopback/dialog.cpp
+++ b/examples/network/loopback/dialog.cpp
@@ -44,12 +44,12 @@
#include "dialog.h"
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
static const int TotalBytes = 50 * 1024 * 1024;
#else
static const int TotalBytes = 5 * 1024 * 1024;
#endif
-static const int PayloadSize = 65536;
+static const int PayloadSize = 64 * 1024; // 64 KB
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
@@ -130,6 +130,7 @@ void Dialog::acceptConnection()
void Dialog::startTransfer()
{
+ // called when the TCP client connected to the loopback server
bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@'));
clientStatusLabel->setText(tr("Connected"));
}
@@ -155,8 +156,11 @@ void Dialog::updateServerProgress()
void Dialog::updateClientProgress(qint64 numBytes)
{
+ // callen when the TCP client has written some bytes
bytesWritten += (int)numBytes;
- if (bytesToWrite > 0)
+
+ // only write more if not finished and when the Qt write buffer is below a certain size.
+ if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize)
bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@'));
clientProgressBar->setMaximum(TotalBytes);