diff options
author | Martin Petersson <Martin.Petersson@nokia.com> | 2012-05-07 12:41:58 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-11 10:38:25 +0200 |
commit | a050bba2f0151beb508fa7ab6f58c25c4e92bfb0 (patch) | |
tree | 82d65e9f02bccac3e847d0824092c779b92369c9 /src/network/access/qhttpthreaddelegate.cpp | |
parent | 1211fd0b6116ca64468780bff12e7902576ab041 (diff) |
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/qhttpthreaddelegate.cpp')
-rw-r--r-- | src/network/access/qhttpthreaddelegate.cpp | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 634340bb54..1ed9f5d3bd 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -194,6 +194,8 @@ QHttpThreadDelegate::QHttpThreadDelegate(QObject *parent) : QObject(parent) , ssl(false) , downloadBufferMaximumSize(0) + , readBufferMaxSize(0) + , bytesEmitted(0) , pendingDownloadData(0) , pendingDownloadProgress(0) , synchronous(false) @@ -349,15 +351,58 @@ void QHttpThreadDelegate::abortRequest() } } +void QHttpThreadDelegate::readBufferSizeChanged(qint64 size) +{ +#ifdef QHTTPTHREADDELEGATE_DEBUG + qDebug() << "QHttpThreadDelegate::readBufferSizeChanged() size " << size; +#endif + if (httpReply) { + httpReply->setDownstreamLimited(size > 0); + httpReply->setReadBufferSize(size); + readBufferMaxSize = size; + } +} + +void QHttpThreadDelegate::readBufferFreed(qint64 size) +{ + if (readBufferMaxSize) { + bytesEmitted -= size; + + QMetaObject::invokeMethod(this, "readyReadSlot", Qt::QueuedConnection); + } +} + void QHttpThreadDelegate::readyReadSlot() { // Don't do in zerocopy case if (!downloadBuffer.isNull()) return; - while (httpReply->readAnyAvailable()) { - pendingDownloadData->fetchAndAddRelease(1); - emit downloadData(httpReply->readAny()); + if (readBufferMaxSize) { + if (bytesEmitted < readBufferMaxSize) { + qint64 sizeEmitted = 0; + while (httpReply->readAnyAvailable() && (sizeEmitted < (readBufferMaxSize-bytesEmitted))) { + if (httpReply->sizeNextBlock() > (readBufferMaxSize-bytesEmitted)) { + sizeEmitted = readBufferMaxSize-bytesEmitted; + bytesEmitted += sizeEmitted; + pendingDownloadData->fetchAndAddRelease(1); + emit downloadData(httpReply->read(sizeEmitted)); + } else { + sizeEmitted = httpReply->sizeNextBlock(); + bytesEmitted += sizeEmitted; + pendingDownloadData->fetchAndAddRelease(1); + emit downloadData(httpReply->readAny()); + } + } + } else { + // We need to wait until we empty data from the read buffer in the reply. + } + + } else { + while (httpReply->readAnyAvailable()) { + pendingDownloadData->fetchAndAddRelease(1); + emit downloadData(httpReply->readAny()); + } } } |