summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorJustin McPherson <justin.mcpherson@nokia.com>2009-06-26 02:20:09 (GMT)
committerJustin McPherson <justin.mcpherson@nokia.com>2009-06-26 02:20:09 (GMT)
commit1e9b20cb6603b61f8d07a9f1da927dbf94f8525a (patch)
tree95a2a56849806d12acc75c8902c1ee54a46ba871 /src/network
parente32bc79d9ab52e5b70e3cd27bddb2bec9c81f5a5 (diff)
parentdb24e82b6b74be303492f186a45d784fcd84fdc6 (diff)
downloadQt-1e9b20cb6603b61f8d07a9f1da927dbf94f8525a.zip
Qt-1e9b20cb6603b61f8d07a9f1da927dbf94f8525a.tar.gz
Qt-1e9b20cb6603b61f8d07a9f1da927dbf94f8525a.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp55
-rw-r--r--src/network/access/qhttpnetworkconnection_p.h12
-rw-r--r--src/network/access/qhttpnetworkreply.cpp13
-rw-r--r--src/network/access/qhttpnetworkreply_p.h6
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp5
-rw-r--r--src/network/access/qnetworkaccessbackend_p.h1
-rw-r--r--src/network/access/qnetworkdiskcache.cpp14
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h1
8 files changed, 75 insertions, 32 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index f0c694d..8409660 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -174,30 +174,43 @@ bool QHttpNetworkConnectionPrivate::isSocketReading(QAbstractSocket *socket) con
}
-void QHttpNetworkConnectionPrivate::appendData(QHttpNetworkReply &reply, const QByteArray &fragment, bool compressed)
+void QHttpNetworkConnectionPrivate::appendUncompressedData(QHttpNetworkReply &reply, const QByteArray &fragment)
{
- QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
- ba->append(fragment);
- return;
+ char *dst = reply.d_func()->responseData.reserve(fragment.size());
+ qMemCopy(dst, fragment.constData(), fragment.size());
}
-qint64 QHttpNetworkConnectionPrivate::bytesAvailable(const QHttpNetworkReply &reply, bool compressed) const
+void QHttpNetworkConnectionPrivate::appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment)
{
- const QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
- return ba->size();
+ reply.d_func()->compressedData.append(fragment);
}
-qint64 QHttpNetworkConnectionPrivate::read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize, bool compressed)
+qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetworkReply &reply) const
{
- QByteArray *ba = (compressed) ? &reply.d_func()->compressedData : &reply.d_func()->responseData;
- if (maxSize == -1 || maxSize >= ba->size()) {
+ return reply.d_func()->responseData.size();
+}
+
+qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const
+{
+ return reply.d_func()->responseData.nextDataBlockSize();
+}
+
+qint64 QHttpNetworkConnectionPrivate::compressedBytesAvailable(const QHttpNetworkReply &reply) const
+{
+ return reply.d_func()->compressedData.size();
+}
+
+qint64 QHttpNetworkConnectionPrivate::read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize)
+{
+ QRingBuffer *rb = &reply.d_func()->responseData;
+ if (maxSize == -1 || maxSize >= rb->size()) {
// read the whole data
- data = *ba;
- ba->clear();
+ data = rb->readAll();
+ rb->clear();
} else {
// read only the requested length
- data = ba->mid(0, maxSize);
- ba->remove(0, maxSize);
+ data.resize(maxSize);
+ rb->read(data.data(), maxSize);
}
return data.size();
}
@@ -524,12 +537,14 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork
Q_ASSERT(socket);
Q_ASSERT(reply);
- qint64 total = bytesAvailable(*reply, true);
+ qint64 total = compressedBytesAvailable(*reply);
if (total >= CHUNK || dataComplete) {
int i = indexOf(socket);
// uncompress the data
QByteArray content, inflated;
- read(*reply, content, -1, true);
+ content = reply->d_func()->compressedData;
+ reply->d_func()->compressedData.clear();
+
int ret = Z_OK;
if (content.size())
ret = reply->d_func()->gunzipBodyPartially(content, inflated);
@@ -537,7 +552,7 @@ bool QHttpNetworkConnectionPrivate::expand(QAbstractSocket *socket, QHttpNetwork
if (ret >= retCheck) {
if (inflated.size()) {
reply->d_func()->totalProgress += inflated.size();
- appendData(*reply, inflated, false);
+ appendUncompressedData(*reply, inflated);
if (shouldEmitSignals(reply)) {
emit reply->readyRead();
// make sure that the reply is valid
@@ -638,7 +653,11 @@ void QHttpNetworkConnectionPrivate::receiveReply(QAbstractSocket *socket, QHttpN
fragment.open(QIODevice::WriteOnly);
bytes = reply->d_func()->readBody(socket, &fragment);
if (bytes) {
- appendData(*reply, fragment.data(), reply->d_func()->autoDecompress);
+ 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)) {
diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h
index 64a6faa..3eb8ffe 100644
--- a/src/network/access/qhttpnetworkconnection_p.h
+++ b/src/network/access/qhttpnetworkconnection_p.h
@@ -254,9 +254,15 @@ public:
bool pendingAuthSignal; // there is an incomplete authentication signal
bool pendingProxyAuthSignal; // there is an incomplete proxy authentication signal
- void appendData(QHttpNetworkReply &reply, const QByteArray &fragment, bool compressed);
- qint64 bytesAvailable(const QHttpNetworkReply &reply, bool compressed = false) const;
- qint64 read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize, bool compressed);
+ void appendUncompressedData(QHttpNetworkReply &reply, const QByteArray &fragment);
+ void appendCompressedData(QHttpNetworkReply &reply, const QByteArray &fragment);
+
+ qint64 uncompressedBytesAvailable(const QHttpNetworkReply &reply) const;
+ qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const;
+ qint64 compressedBytesAvailable(const QHttpNetworkReply &reply) const;
+
+ qint64 read(QHttpNetworkReply &reply, QByteArray &data, qint64 maxSize);
+
void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
void allDone(QAbstractSocket *socket, QHttpNetworkReply *reply);
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index c4d4a9c..202bdea 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -162,7 +162,16 @@ qint64 QHttpNetworkReply::bytesAvailable() const
{
Q_D(const QHttpNetworkReply);
if (d->connection)
- return d->connection->d_func()->bytesAvailable(*this);
+ return d->connection->d_func()->uncompressedBytesAvailable(*this);
+ else
+ return -1;
+}
+
+qint64 QHttpNetworkReply::bytesAvailableNextBlock() const
+{
+ Q_D(const QHttpNetworkReply);
+ if (d->connection)
+ return d->connection->d_func()->uncompressedBytesAvailableNextBlock(*this);
else
return -1;
}
@@ -172,7 +181,7 @@ QByteArray QHttpNetworkReply::read(qint64 maxSize)
Q_D(QHttpNetworkReply);
QByteArray data;
if (d->connection)
- d->connection->d_func()->read(*this, data, maxSize, false);
+ d->connection->d_func()->read(*this, data, maxSize);
return data;
}
diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h
index 08bd886..69c9158 100644
--- a/src/network/access/qhttpnetworkreply_p.h
+++ b/src/network/access/qhttpnetworkreply_p.h
@@ -79,6 +79,7 @@ static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header
#include <private/qhttpnetworkheader_p.h>
#include <private/qhttpnetworkrequest_p.h>
#include <private/qauthenticator_p.h>
+#include <private/qringbuffer_p.h>
QT_BEGIN_NAMESPACE
@@ -120,6 +121,7 @@ public:
QString reasonPhrase() const;
qint64 bytesAvailable() const;
+ qint64 bytesAvailableNextBlock() const;
QByteArray read(qint64 maxSize = -1);
bool isFinished() const;
@@ -193,7 +195,7 @@ public:
qint64 bodyLength;
qint64 contentRead;
qint64 totalProgress;
- QByteArray fragment;
+ QByteArray fragment; // used for header, status, chunk header etc, not for reply data
qint64 currentChunkSize;
qint64 currentChunkRead;
QPointer<QHttpNetworkConnection> connection;
@@ -204,7 +206,7 @@ public:
#endif
bool autoDecompress;
- QByteArray responseData; // uncompressed body
+ QRingBuffer responseData; // uncompressed body
QByteArray compressedData; // compressed body (temporary)
bool requestIsPrepared;
};
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index bea0c72..88ae894 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -217,11 +217,6 @@ qint64 QNetworkAccessBackend::nextDownstreamBlockSize() const
return reply->nextDownstreamBlockSize();
}
-qint64 QNetworkAccessBackend::downstreamBytesToConsume() const
-{
- return reply->writeBuffer.size();
-}
-
void QNetworkAccessBackend::writeDownstreamData(const QByteArray &data)
{
reply->appendDownstreamData(data);
diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h
index e6d16ca..21cb4a6 100644
--- a/src/network/access/qnetworkaccessbackend_p.h
+++ b/src/network/access/qnetworkaccessbackend_p.h
@@ -166,7 +166,6 @@ protected:
// these functions control the downstream mechanism
// that is, data that has come via the connection and is going out the backend
qint64 nextDownstreamBlockSize() const;
- qint64 downstreamBytesToConsume() const;
void writeDownstreamData(const QByteArray &data);
public slots:
diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp
index 5df6b0f..50aaa6a 100644
--- a/src/network/access/qnetworkdiskcache.cpp
+++ b/src/network/access/qnetworkdiskcache.cpp
@@ -81,6 +81,20 @@ QT_BEGIN_NAMESPACE
use on the system to 50MB.
Note you have to set the cache directory before it will work.
+
+ A network disk cache can be enabled by:
+
+ \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 0
+
+ When sending requests, to control the preference of when to use the cache
+ and when to use the network, consider the following:
+
+ \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 1
+
+ To check whether the response came from the cache or from the network, the
+ following can be applied:
+
+ \snippet doc/src/snippets/code/src_network_access_qnetworkdiskcache.cpp 2
*/
/*!
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 2ee25ad..4d75526 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -166,7 +166,6 @@ public:
#endif
QRingBuffer readBuffer;
- QRingBuffer writeBuffer;
qint64 bytesDownloaded;
qint64 lastBytesDownloaded;
qint64 bytesUploaded;