diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-26 13:40:57 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2009-06-29 09:13:25 (GMT) |
commit | 9daf22e645106d09b32a60e5cfe65672e6b64f91 (patch) | |
tree | 0defdd7e4b795c4f763ea6f3ca154fbd052632a6 /src/network/access/qhttpnetworkreply.cpp | |
parent | dae562ea1bcc2e65d14f6a4404b7544295f1a910 (diff) | |
download | Qt-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/qhttpnetworkreply.cpp')
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 202bdea..72aec99 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; } |