summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttpnetworkreply.cpp
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-06-26 15:40:57 +0200
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-06-29 11:13:25 +0200
commit9daf22e645106d09b32a60e5cfe65672e6b64f91 (patch)
tree0defdd7e4b795c4f763ea6f3ca154fbd052632a6 /src/network/access/qhttpnetworkreply.cpp
parentdae562ea1bcc2e65d14f6a4404b7544295f1a910 (diff)
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/qhttpnetworkreply.cpp')
-rw-r--r--src/network/access/qhttpnetworkreply.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 202bdea8c4..72aec997f7 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -549,6 +549,30 @@ bool QHttpNetworkReplyPrivate::connectionCloseEnabled()
headerField("proxy-connection").toLower().contains("close"));
}
+// note this function can only be used for non-chunked, non-compressed with
+// known content length
+qint64 QHttpNetworkReplyPrivate::readBodyFast(QAbstractSocket *socket, QRingBuffer *rb)
+{
+ quint64 toBeRead = qMin(socket->bytesAvailable(), bodyLength - contentRead);
+ char* dst = rb->reserve(toBeRead);
+ qint64 haveRead = socket->read(dst, toBeRead);
+ if (haveRead == -1) {
+ rb->chop(toBeRead);
+ return 0; // ### error checking here;
+ }
+
+ rb->chop(toBeRead - haveRead);
+
+ if (contentRead + haveRead == bodyLength) {
+ state = AllDoneState;
+ socket->readAll(); // Read the rest to clean (CRLF) ### will break pipelining
+ }
+
+ contentRead += haveRead;
+ return haveRead;
+}
+
+
qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QIODevice *out)
{
qint64 bytes = 0;
@@ -562,7 +586,7 @@ qint64 QHttpNetworkReplyPrivate::readBody(QAbstractSocket *socket, QIODevice *ou
bytes += readReplyBodyRaw(socket, out, socket->bytesAvailable());
}
if (state == AllDoneState)
- socket->readAll(); // Read the rest to clean (CRLF)
+ socket->readAll(); // Read the rest to clean (CRLF) ### will break pipelining
contentRead += bytes;
return bytes;
}