summaryrefslogtreecommitdiffstats
path: root/src/network/access
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/access')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp39
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp14
-rw-r--r--src/network/access/qnetworkaccesscachebackend.cpp1
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp3
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp36
-rw-r--r--src/network/access/qnetworkreplyimpl_p.h3
6 files changed, 49 insertions, 47 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index da9ec09..bd6fa57 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -425,32 +425,25 @@ void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socke
int i = indexOf(socket);
if (!highPriorityQueue.isEmpty()) {
- for (int j = highPriorityQueue.count() - 1; j >= 0; --j) {
- HttpMessagePair &messagePair = highPriorityQueue[j];
- if (!messagePair.second->d_func()->requestIsPrepared)
- prepareRequest(messagePair);
-
- channels[i].request = messagePair.first;
- channels[i].reply = messagePair.second;
- // remove before sendRequest! else we might pipeline the same request again
- highPriorityQueue.removeAt(j);
- channels[i].sendRequest();
- return;
- }
+ // remove from queue before sendRequest! else we might pipeline the same request again
+ HttpMessagePair messagePair = highPriorityQueue.takeLast();
+ if (!messagePair.second->d_func()->requestIsPrepared)
+ prepareRequest(messagePair);
+ channels[i].request = messagePair.first;
+ channels[i].reply = messagePair.second;
+ channels[i].sendRequest();
+ return;
}
if (!lowPriorityQueue.isEmpty()) {
- for (int j = lowPriorityQueue.count() - 1; j >= 0; --j) {
- HttpMessagePair &messagePair = lowPriorityQueue[j];
- if (!messagePair.second->d_func()->requestIsPrepared)
- prepareRequest(messagePair);
- channels[i].request = messagePair.first;
- channels[i].reply = messagePair.second;
- // remove before sendRequest! else we might pipeline the same request again
- lowPriorityQueue.removeAt(j);
- channels[i].sendRequest();
- return;
- }
+ // remove from queue before sendRequest! else we might pipeline the same request again
+ HttpMessagePair messagePair = lowPriorityQueue.takeLast();
+ if (!messagePair.second->d_func()->requestIsPrepared)
+ prepareRequest(messagePair);
+ channels[i].request = messagePair.first;
+ channels[i].reply = messagePair.second;
+ channels[i].sendRequest();
+ return;
}
}
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index b624c24..be7896b 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -92,8 +92,11 @@ QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessM
QNetworkRequest::PreferNetwork).toInt());
if (mode == QNetworkRequest::AlwaysCache
&& (op == QNetworkAccessManager::GetOperation
- || op == QNetworkAccessManager::HeadOperation))
- return new QNetworkAccessCacheBackend;
+ || op == QNetworkAccessManager::HeadOperation)) {
+ QNetworkAccessBackend *backend = new QNetworkAccessCacheBackend;
+ backend->manager = this;
+ return backend;
+ }
if (!factoryDataShutdown) {
QMutexLocker locker(&factoryData()->mutex);
@@ -111,7 +114,6 @@ QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessM
return 0;
}
-
QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice()
{
QNonContiguousByteDevice* device = 0;
@@ -143,6 +145,8 @@ void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 byt
}
QNetworkAccessBackend::QNetworkAccessBackend()
+ : manager(0)
+ , reply(0)
{
}
@@ -205,7 +209,9 @@ QList<QNetworkProxy> QNetworkAccessBackend::proxyList() const
QAbstractNetworkCache *QNetworkAccessBackend::networkCache() const
{
- return reply->networkCache; // should be the same as manager->networkCache
+ if (!manager)
+ return 0;
+ return manager->networkCache;
}
void QNetworkAccessBackend::setCachingEnabled(bool enable)
diff --git a/src/network/access/qnetworkaccesscachebackend.cpp b/src/network/access/qnetworkaccesscachebackend.cpp
index df66c9d..2be10db 100644
--- a/src/network/access/qnetworkaccesscachebackend.cpp
+++ b/src/network/access/qnetworkaccesscachebackend.cpp
@@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
QNetworkAccessCacheBackend::QNetworkAccessCacheBackend()
: QNetworkAccessBackend()
+ , device(0)
{
}
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index d925e77..bc01e82 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -711,9 +711,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
// fourth step: setup the reply
priv->setup(op, request, outgoingData);
- if (request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt() !=
- QNetworkRequest::AlwaysNetwork)
- priv->setNetworkCache(d->networkCache);
#ifndef QT_NO_NETWORKPROXY
QList<QNetworkProxy> proxyList = d->queryProxy(QNetworkProxyQuery(request.url()));
priv->proxyList = proxyList;
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 3b0948b..a60a8dd 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE
inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
: backend(0), outgoingData(0), outgoingDataBuffer(0),
- copyDevice(0), networkCache(0),
+ copyDevice(0),
cacheEnabled(false), cacheSaveDevice(0),
notificationHandlingPaused(false),
bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1),
@@ -252,11 +252,6 @@ void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const
q->QIODevice::open(QIODevice::ReadOnly);
}
-void QNetworkReplyImplPrivate::setNetworkCache(QAbstractNetworkCache *nc)
-{
- networkCache = nc;
-}
-
void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification)
{
Q_Q(QNetworkReplyImpl);
@@ -318,17 +313,28 @@ void QNetworkReplyImplPrivate::resumeNotificationHandling()
QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated));
}
+QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const
+{
+ if (!backend)
+ return 0;
+ return backend->networkCache();
+}
+
void QNetworkReplyImplPrivate::createCache()
{
// check if we can save and if we're allowed to
- if (!networkCache || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool())
+ if (!networkCache()
+ || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool()
+ || request.attribute(QNetworkRequest::CacheLoadControlAttribute,
+ QNetworkRequest::PreferNetwork).toInt()
+ == QNetworkRequest::AlwaysNetwork)
return;
cacheEnabled = true;
}
bool QNetworkReplyImplPrivate::isCachingEnabled() const
{
- return (cacheEnabled && networkCache != 0);
+ return (cacheEnabled && networkCache() != 0);
}
void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
@@ -352,7 +358,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- "
"backend %s probably needs to be fixed",
backend->metaObject()->className());
- networkCache->remove(url);
+ networkCache()->remove(url);
cacheSaveDevice = 0;
cacheEnabled = false;
}
@@ -361,9 +367,9 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable)
void QNetworkReplyImplPrivate::completeCacheSave()
{
if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) {
- networkCache->remove(url);
+ networkCache()->remove(url);
} else if (cacheEnabled && cacheSaveDevice) {
- networkCache->insert(cacheSaveDevice);
+ networkCache()->insert(cacheSaveDevice);
}
cacheSaveDevice = 0;
cacheEnabled = false;
@@ -410,15 +416,15 @@ void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data)
metaData.setAttributes(attributes);
}
- cacheSaveDevice = networkCache->prepare(metaData);
+ cacheSaveDevice = networkCache()->prepare(metaData);
if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
if (cacheSaveDevice && !cacheSaveDevice->isOpen())
qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "
"class %s probably needs to be fixed",
- networkCache->metaObject()->className());
+ networkCache()->metaObject()->className());
- networkCache->remove(url);
+ networkCache()->remove(url);
cacheSaveDevice = 0;
cacheEnabled = false;
}
@@ -566,7 +572,7 @@ QNetworkReplyImpl::~QNetworkReplyImpl()
{
Q_D(QNetworkReplyImpl);
if (d->isCachingEnabled())
- d->networkCache->remove(url());
+ d->networkCache()->remove(url());
}
void QNetworkReplyImpl::abort()
diff --git a/src/network/access/qnetworkreplyimpl_p.h b/src/network/access/qnetworkreplyimpl_p.h
index 8cda7a4..04f8aa8 100644
--- a/src/network/access/qnetworkreplyimpl_p.h
+++ b/src/network/access/qnetworkreplyimpl_p.h
@@ -131,7 +131,6 @@ public:
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request,
QIODevice *outgoingData);
- void setNetworkCache(QAbstractNetworkCache *networkCache);
void pauseNotificationHandling();
void resumeNotificationHandling();
@@ -160,7 +159,7 @@ public:
QIODevice *outgoingData;
QRingBuffer *outgoingDataBuffer;
QIODevice *copyDevice;
- QAbstractNetworkCache *networkCache;
+ QAbstractNetworkCache *networkCache() const;
bool cacheEnabled;
QIODevice *cacheSaveDevice;