summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttpnetworkconnection.cpp
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-06-26 13:40:57 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-06-29 09:13:25 (GMT)
commit9daf22e645106d09b32a60e5cfe65672e6b64f91 (patch)
tree0defdd7e4b795c4f763ea6f3ca154fbd052632a6 /src/network/access/qhttpnetworkconnection.cpp
parentdae562ea1bcc2e65d14f6a4404b7544295f1a910 (diff)
downloadQt-9daf22e645106d09b32a60e5cfe65672e6b64f91.zip
Qt-9daf22e645106d09b32a60e5cfe65672e6b64f91.tar.gz
Qt-9daf22e645106d09b32a60e5cfe65672e6b64f91.tar.bz2
QNAM HTTP Code: Properly use the QRingBuffer for some kind of data.
Use the QRingBuffer properly when reading known-size, non-chunked, non-compressed data from HTTP. Reviewed-by: Thiago Macieira
Diffstat (limited to 'src/network/access/qhttpnetworkconnection.cpp')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp76
1 files changed, 49 insertions, 27 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 8409660..56caca9 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -649,36 +649,58 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN
}
break;
case QHttpNetworkReplyPrivate::ReadingDataState: {
- QBuffer fragment;
- fragment.open(QIODevice::WriteOnly);
- bytes = reply->d_func()->readBody(socket, &fragment);
- if (bytes) {
- if (reply->d_func()->autoDecompress)
- appendCompressedData(*reply, fragment.data());
- else
- appendUncompressedData(*reply, fragment.data());
-
- if (!reply->d_func()->autoDecompress) {
- reply->d_func()->totalProgress += fragment.size();
- if (shouldEmitSignals(reply)) {
- emit reply->readyRead();
- // make sure that the reply is valid
- if (channels[i].reply != reply)
- return;
- // emit dataReadProgress signal (signal is currently not connected
- // to the rest of QNAM) since readProgress of the
- // QNonContiguousByteDevice is used
- emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength);
- // make sure that the reply is valid
- if (channels[i].reply != reply)
- return;
- }
+ if (!reply->d_func()->isChunked() && !reply->d_func()->autoDecompress
+ && reply->d_func()->bodyLength > 0) {
+ // bulk files like images should fulfill these properties and
+ // we can therefore save on memory copying
+ bytes = reply->d_func()->readBodyFast(socket, &reply->d_func()->responseData);
+ reply->d_func()->totalProgress += bytes;
+ if (shouldEmitSignals(reply)) {
+ emit reply->readyRead();
+ // make sure that the reply is valid
+ if (channels[i].reply != reply)
+ return;
+ emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength);
+ // make sure that the reply is valid
+ if (channels[i].reply != reply)
+ return;
}
+ }
+ else
+ {
+ // use the traditional slower reading (for compressed encoding, chunked encoding,
+ // no content-length etc)
+ QBuffer fragment;
+ fragment.open(QIODevice::WriteOnly);
+ bytes = reply->d_func()->readBody(socket, &fragment);
+ if (bytes) {
+ if (reply->d_func()->autoDecompress)
+ appendCompressedData(*reply, fragment.data());
+ else
+ appendUncompressedData(*reply, fragment.data());
+
+ if (!reply->d_func()->autoDecompress) {
+ reply->d_func()->totalProgress += fragment.size();
+ if (shouldEmitSignals(reply)) {
+ emit reply->readyRead();
+ // make sure that the reply is valid
+ if (channels[i].reply != reply)
+ return;
+ // emit dataReadProgress signal (signal is currently not connected
+ // to the rest of QNAM) since readProgress of the
+ // QNonContiguousByteDevice is used
+ emit reply->dataReadProgress(reply->d_func()->totalProgress, reply->d_func()->bodyLength);
+ // make sure that the reply is valid
+ if (channels[i].reply != reply)
+ return;
+ }
+ }
#ifndef QT_NO_COMPRESS
- else if (!expand(socket, reply, false)) { // expand a chunk if possible
- return; // ### expand failed
- }
+ else if (!expand(socket, reply, false)) { // expand a chunk if possible
+ return; // ### expand failed
+ }
#endif
+ }
}
if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState)
break;