diff options
author | David Faure <david.faure@kdab.com> | 2013-09-11 00:41:31 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-20 09:30:05 +0100 |
commit | 13c246ee119fdb10d91f509b968a221d4fc1d8ba (patch) | |
tree | a3a526e62e7ac7044bad9df2a9cdf37f31aacc62 /tests | |
parent | 8fb497d1f49d382cd0a26e396bc17d1edd615fb4 (diff) |
QAbstractSocket: fix setReadBufferSize from readyRead slot.
In a slot connected to readyRead, if the app detects that the
buffer size is too small and increases it, it expects that
readyRead() will be emitted again.
setReadBufferSize() doesn't re-enable the socket notifier when
calling from within readyRead, and readyRead itself was missing
the code to do it.
Change-Id: Ia00a3066ad3ba09d5cfae0716adc5691ae96c3fa
Done-with: Thiago
Reviewed-by: Peter Hartmann <phartmann@blackberry.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index f4eac0d6b8..e589d520cb 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -189,6 +189,7 @@ private slots: void connectToMultiIP(); void moveToThread0(); void increaseReadBufferSize(); + void increaseReadBufferSizeFromSlot(); void taskQtBug5799ConnectionErrorWaitForConnected(); void taskQtBug5799ConnectionErrorEventLoop(); void taskQtBug7054TimeoutErrorResetting(); @@ -225,6 +226,7 @@ protected slots: #endif void earlySocketBytesSent(qint64 bytes); void earlySocketReadyRead(); + void slotIncreaseReadBufferSizeReadyRead(); private: QByteArray expectedReplyIMAP(); @@ -2459,6 +2461,57 @@ void tst_QTcpSocket::increaseReadBufferSize() delete active; } +void tst_QTcpSocket::increaseReadBufferSizeFromSlot() // like KIO's socketconnectionbackend +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; //proxy not useful for localhost test case + QTcpServer server; + QTcpSocket *active = newSocket(); + connect(active, SIGNAL(readyRead()), SLOT(slotIncreaseReadBufferSizeReadyRead())); + + // connect two sockets to each other: + QVERIFY(server.listen(QHostAddress::LocalHost)); + active->connectToHost("127.0.0.1", server.serverPort()); + QVERIFY(active->waitForConnected(5000)); + QVERIFY(server.waitForNewConnection(5000)); + + QTcpSocket *passive = server.nextPendingConnection(); + QVERIFY(passive); + + // now write 512 bytes of data on one end + QByteArray data(512, 'a'); + passive->write(data); + QVERIFY2(passive->waitForBytesWritten(5000), "Network timeout"); + + // set the read buffer size to less than what was written, + // and increase it from the slot, first to 384 then to 1024. + active->setReadBufferSize(256); + enterLoop(10); + QVERIFY2(!timeout(), "Network timeout"); + QCOMPARE(active->bytesAvailable(), qint64(data.size())); + + // drain it and compare + QCOMPARE(active->readAll(), data); + + delete active; +} + +void tst_QTcpSocket::slotIncreaseReadBufferSizeReadyRead() +{ + QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender()); + const int currentBufferSize = socket->readBufferSize(); + QCOMPARE(currentBufferSize, socket->bytesAvailable()); + if (currentBufferSize == 256) + socket->setReadBufferSize(384); + else if (currentBufferSize == 384) + socket->setReadBufferSize(512); + else if (currentBufferSize == 512) + exitLoopSlot(); + else // should not happen + qFatal("buffer size was %d", currentBufferSize); +} + void tst_QTcpSocket::taskQtBug5799ConnectionErrorWaitForConnected() { QFETCH_GLOBAL(bool, setProxy); |