diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-01-18 03:58:47 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-02-03 06:53:25 (GMT) |
commit | 28f95681f4a6fc2e95180f573b658637a82c4c12 (patch) | |
tree | 844f8bb7edca2ee0c35e742fbe156345e9952c02 /src | |
parent | e80295fff0836268d357488feaefb874b458e8ab (diff) | |
download | Qt-28f95681f4a6fc2e95180f573b658637a82c4c12.zip Qt-28f95681f4a6fc2e95180f573b658637a82c4c12.tar.gz Qt-28f95681f4a6fc2e95180f573b658637a82c4c12.tar.bz2 |
Start adding network session support into QNetworkAccessManager.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qnetworkaccessbackend.cpp | 30 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessbackend_p.h | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 30 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager.h | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkaccessmanager_p.h | 5 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyimpl.cpp | 4 |
6 files changed, 75 insertions, 2 deletions
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 8ac64d2..54d9dbd 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -49,6 +49,8 @@ #include "qnetworkaccesscachebackend_p.h" #include "qabstractnetworkcache.h" +#include "qnetworksession.h" +#include "qhostinfo.h" #include "private/qnoncontiguousbytedevice_p.h" @@ -341,4 +343,32 @@ void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors) #endif } +void QNetworkAccessBackend::start() +{ + qDebug() << "Checking for localhost"; + QHostInfo hostInfo = QHostInfo::fromName(reply->url.host()); + foreach (const QHostAddress &address, hostInfo.addresses()) { + if (address == QHostAddress::LocalHost || + address == QHostAddress::LocalHostIPv6) { + // Don't need session for local host access. + qDebug() << "Access is to localhost"; + open(); + return; + } + } + + qDebug() << "Connecting session signals"; + connect(manager->session, SIGNAL(opened()), this, SLOT(sessionOpened())); + + qDebug() << "Open session if required"; + if (!manager->session->isOpen()) + manager->session->open(); +} + +void QNetworkAccessBackend::sessionOpened() +{ + qDebug() << "Session opened, calling open()"; + open(); +} + QT_END_NAMESPACE diff --git a/src/network/access/qnetworkaccessbackend_p.h b/src/network/access/qnetworkaccessbackend_p.h index 43d993c..04cc5b0 100644 --- a/src/network/access/qnetworkaccessbackend_p.h +++ b/src/network/access/qnetworkaccessbackend_p.h @@ -111,6 +111,7 @@ public: // socket). virtual void open() = 0; + virtual void start(); virtual void closeDownstreamChannel() = 0; virtual bool waitForDownstreamReadyRead(int msecs) = 0; @@ -186,6 +187,9 @@ protected slots: void sslErrors(const QList<QSslError> &errors); void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); +private slots: + void sessionOpened(); + private: friend class QNetworkAccessManager; friend class QNetworkAccessManagerPrivate; diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index e16aedc..38ab1c6 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -59,6 +59,8 @@ #include "QtCore/qvector.h" #include "QtNetwork/qauthenticator.h" #include "QtNetwork/qsslconfiguration.h" +#include "QtNetwork/qnetworkconfigmanager.h" +#include "QtNetwork/qnetworksession.h" QT_BEGIN_NAMESPACE @@ -346,6 +348,9 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) : QObject(*new QNetworkAccessManagerPrivate, parent) { ensureInitialized(); + + d_func()->session = + new QNetworkSession(QNetworkConfigurationManager().defaultConfiguration(), this); } /*! @@ -665,6 +670,31 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ } /*! + \since 4.7 + + Sets the network configuration that will be used to \a config. + + \sa configuration() +*/ +void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) +{ + delete d_func()->session; + d_func()->session = new QNetworkSession(config, this); +} + +/*! + \since 4.7 + + Returns the network configuration. + + \sa setConfiguration() +*/ +QNetworkConfiguration QNetworkAccessManager::configuration() const +{ + return d_func()->session->configuration(); +} + +/*! Returns a new QNetworkReply object to handle the operation \a op and request \a req. The device \a outgoingData is always 0 for Get and Head requests, but is the value passed to post() and put() in diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index d2fe527..8e1c3b6 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -62,6 +62,7 @@ class QNetworkReply; class QNetworkProxy; class QNetworkProxyFactory; class QSslError; +class QNetworkConfiguration; class QNetworkReplyImplPrivate; class QNetworkAccessManagerPrivate; @@ -103,6 +104,9 @@ public: QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data); QNetworkReply *deleteResource(const QNetworkRequest &request); + void setConfiguration(const QNetworkConfiguration &config); + QNetworkConfiguration configuration() const; + Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 1749373..4eeff4b 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -65,6 +65,7 @@ class QAuthenticator; class QAbstractNetworkCache; class QNetworkAuthenticationCredential; class QNetworkCookieJar; +class QNetworkSession; class QNetworkAccessManagerPrivate: public QObjectPrivate { @@ -74,7 +75,8 @@ public: #ifndef QT_NO_NETWORKPROXY proxyFactory(0), #endif - cookieJarCreated(false) + cookieJarCreated(false), + session(0) { } ~QNetworkAccessManagerPrivate(); @@ -112,6 +114,7 @@ public: bool cookieJarCreated; + QNetworkSession *session; // this cache can be used by individual backends to cache e.g. their TCP connections to a server // and use the connections for multiple requests. diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 59c7d76..f097a2b 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -82,7 +82,9 @@ void QNetworkReplyImplPrivate::_q_startOperation() return; } - backend->open(); + backend->start(); + + //backend->open(); if (state != Finished) { if (operation == QNetworkAccessManager::GetOperation) pendingNotifications.append(NotifyDownstreamReadyWrite); |