summaryrefslogtreecommitdiff
path: root/src/network/access/qhttpnetworkreply.cpp
diff options
context:
space:
mode:
authorMartin Petersson <Martin.Petersson@nokia.com>2012-05-07 12:41:58 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-11 10:38:25 +0200
commita050bba2f0151beb508fa7ab6f58c25c4e92bfb0 (patch)
tree82d65e9f02bccac3e847d0824092c779b92369c9 /src/network/access/qhttpnetworkreply.cpp
parent1211fd0b6116ca64468780bff12e7902576ab041 (diff)
downloadqtbase-a050bba2f0151beb508fa7ab6f58c25c4e92bfb0.tar.gz
QNetworkReply::setReadBufferSize fix for threaded http
Added the setReadBufferSize functionallity again by limiting the amount that the delegate read from the channel. Each time that data is fetched from the reply buffer, we communicate back to the thread so that more data can be fetched. Task-number: QTBUG-25327 Change-Id: I2f9950196e64acd09bc8da50c1116f2c9deacad4 Reviewed-by: Shane Kearns <shane.kearns@accenture.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/network/access/qhttpnetworkreply.cpp')
-rw-r--r--src/network/access/qhttpnetworkreply.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 39204163f2..4f358ed178 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -206,6 +206,19 @@ QByteArray QHttpNetworkReply::readAll()
return d->responseData.readAll();
}
+QByteArray QHttpNetworkReply::read(qint64 amount)
+{
+ Q_D(QHttpNetworkReply);
+ return d->responseData.read(amount);
+}
+
+
+qint64 QHttpNetworkReply::sizeNextBlock()
+{
+ Q_D(QHttpNetworkReply);
+ return d->responseData.sizeNextBlock();
+}
+
void QHttpNetworkReply::setDownstreamLimited(bool dsl)
{
Q_D(QHttpNetworkReply);
@@ -213,6 +226,12 @@ void QHttpNetworkReply::setDownstreamLimited(bool dsl)
d->connection->d_func()->readMoreLater(this);
}
+void QHttpNetworkReply::setReadBufferSize(qint64 size)
+{
+ Q_D(QHttpNetworkReply);
+ d->readBufferMaxSize = size;
+}
+
bool QHttpNetworkReply::supportsUserProvidedDownloadBuffer()
{
Q_D(QHttpNetworkReply);
@@ -258,7 +277,7 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl)
connectionCloseEnabled(true),
forceConnectionCloseEnabled(false),
lastChunkRead(false),
- currentChunkSize(0), currentChunkRead(0), connection(0),
+ currentChunkSize(0), currentChunkRead(0), readBufferMaxSize(0), connection(0),
autoDecompress(false), responseData(), requestIsPrepared(false)
,pipeliningUsed(false), downstreamLimited(false)
,userProvidedDownloadBuffer(0)
@@ -598,6 +617,10 @@ qint64 QHttpNetworkReplyPrivate::readBodyFast(QAbstractSocket *socket, QByteData
{
qint64 toBeRead = qMin(socket->bytesAvailable(), bodyLength - contentRead);
+ if (readBufferMaxSize)
+ toBeRead = qMin(toBeRead, readBufferMaxSize);
+
+
QByteArray bd;
bd.resize(toBeRead);
qint64 haveRead = socket->read(bd.data(), toBeRead);
@@ -698,6 +721,9 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyRaw(QAbstractSocket *socket, QByte
int toBeRead = qMin<qint64>(128*1024, qMin<qint64>(size, socket->bytesAvailable()));
+ if (readBufferMaxSize)
+ toBeRead = qMin<qint64>(toBeRead, readBufferMaxSize);
+
while (toBeRead > 0) {
QByteArray byteData;
byteData.resize(toBeRead);
@@ -723,6 +749,10 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QAbstractSocket *socket, Q
{
qint64 bytes = 0;
while (socket->bytesAvailable()) {
+
+ if (readBufferMaxSize && (bytes > readBufferMaxSize))
+ break;
+
if (!lastChunkRead && currentChunkRead >= currentChunkSize) {
// For the first chunk and when we're done with a chunk
currentChunkSize = 0;