diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-03-15 14:26:41 (GMT) |
---|---|---|
committer | Samuli Piippo <samuli.piippo@digia.com> | 2011-06-09 10:05:14 (GMT) |
commit | 708205d04d8add5f8c4d6c588a814868b53d8fc2 (patch) | |
tree | 90f071b94ab0539bddf8583ea6f65d7f0734c19f | |
parent | 2f12b5a5d23197b04f4807978704e7c79d5da594 (diff) | |
download | Qt-708205d04d8add5f8c4d6c588a814868b53d8fc2.zip Qt-708205d04d8add5f8c4d6c588a814868b53d8fc2.tar.gz Qt-708205d04d8add5f8c4d6c588a814868b53d8fc2.tar.bz2 |
QNetworkReply: Fix canReadLine()
Reviewed-by: Peter Hartmann
(cherry picked from commit dd6c5cad88a56fb3a342fe9d4fc3b113ffe3fd53)
-rw-r--r-- | src/corelib/tools/qbytedata_p.h | 7 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 7 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl_p.h | 3 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 17 |
4 files changed, 33 insertions, 1 deletions
diff --git a/src/corelib/tools/qbytedata_p.h b/src/corelib/tools/qbytedata_p.h index fb1fa64..f59d8eb 100644 --- a/src/corelib/tools/qbytedata_p.h +++ b/src/corelib/tools/qbytedata_p.h @@ -206,6 +206,13 @@ public: { return buffers[i]; } + + inline bool canReadLine() const { + for (int i = 0; i < buffers.length(); i++) + if (buffers.at(i).contains('\n')) + return true; + return false; + } }; QT_END_NAMESPACE diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 792a2c0..e07c0b6 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -662,6 +662,13 @@ void QNetworkReplyImpl::close() d->finished(); } +bool QNetworkReplyImpl::canReadLine () const +{ + Q_D(const QNetworkReplyImpl); + return QNetworkReply::canReadLine() || d->readBuffer.canReadLine(); +} + + /*! Returns the number of bytes available for reading with QIODevice::read(). The number of bytes available may grow until diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h index 8684b32..3ab86c5 100644 --- a/src/network/access/qnetworkreplyimpl_p.h +++ b/src/network/access/qnetworkreplyimpl_p.h @@ -77,10 +77,11 @@ public: ~QNetworkReplyImpl(); virtual void abort(); - // reimplemented from QNetworkReply + // reimplemented from QNetworkReply / QIODevice virtual void close(); virtual qint64 bytesAvailable() const; virtual void setReadBufferSize(qint64 size); + virtual bool canReadLine () const; virtual qint64 readData(char *data, qint64 maxlen); virtual bool event(QEvent *); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 5d095c2..ed9c815 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -235,6 +235,8 @@ private Q_SLOTS: void lastModifiedHeaderForFile(); void lastModifiedHeaderForHttp(); + void httpCanReadLine(); + void rateControl_data(); void rateControl(); @@ -3298,6 +3300,21 @@ void tst_QNetworkReply::lastModifiedHeaderForHttp() QCOMPARE(header, realDate); } +void tst_QNetworkReply::httpCanReadLine() +{ + QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt")); + QNetworkReplyPtr reply = manager.get(request); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + + QVERIFY(reply->canReadLine()); + QVERIFY(!reply->readAll().isEmpty()); + QVERIFY(!reply->canReadLine()); +} + void tst_QNetworkReply::rateControl_data() { QTest::addColumn<int>("rate"); |