summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-03-09 21:27:45 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-09 22:37:18 +0100
commit849b760c9047a9306d5a63d7fa60d0ab2431e1dd (patch)
tree5753c9f690fdb826a89075ea02810929c04a047a /src/network
parentd4db23eb4d9113338ead0ed5f1c5b788681d8f43 (diff)
Revert "QNam: only init channels when needed."
This reverts commit ff25691d00d634068c6389f8f1607d7cc95ac5be. The change broke qtdeclarative. Several autotests crash because QHttpNetworkConnection::transparentProxy() calls proxy() on a null socket. Task-number: QTBUG-24717 Change-Id: I57e3ccf5d20683f59cf7450083d1fcb3fa1c40fe Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp106
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp67
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel_p.h11
3 files changed, 46 insertions, 138 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 890072eb7e..6aa3a5a5f4 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -123,8 +123,8 @@ void QHttpNetworkConnectionPrivate::init()
//push session down to channels
channels[i].networkSession = networkSession;
#endif
+ channels[i].init();
}
-
delayedConnectionTimer.setSingleShot(true);
QObject::connect(&delayedConnectionTimer, SIGNAL(timeout()), q, SLOT(_q_connectDelayedChannel()));
}
@@ -135,14 +135,12 @@ void QHttpNetworkConnectionPrivate::pauseConnection()
// Disable all socket notifiers
for (int i = 0; i < channelCount; i++) {
- if (channels[i].socket) {
#ifndef QT_NO_SSL
- if (encrypt)
- QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
- else
+ if (encrypt)
+ QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
+ else
#endif
- QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket);
- }
+ QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket);
}
}
@@ -151,18 +149,16 @@ void QHttpNetworkConnectionPrivate::resumeConnection()
state = RunningState;
// Enable all socket notifiers
for (int i = 0; i < channelCount; i++) {
- if (channels[i].socket) {
#ifndef QT_NO_SSL
- if (encrypt)
- QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
- else
+ if (encrypt)
+ QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket));
+ else
#endif
- QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket);
+ QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket);
- // Resume pending upload if needed
- if (channels[i].state == QHttpNetworkConnectionChannel::WritingState)
- QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection);
- }
+ // Resume pending upload if needed
+ if (channels[i].state == QHttpNetworkConnectionChannel::WritingState)
+ QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection);
}
// queue _q_startNextRequest
@@ -350,15 +346,11 @@ void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket,
QNetworkReply::NetworkError errorCode)
{
Q_Q(QHttpNetworkConnection);
-
- int i = 0;
- if (socket)
- i = indexOf(socket);
-
- if (reply) {
+ if (socket && reply) {
// this error matters only to this reply
reply->d_func()->errorString = errorDetail(errorCode, socket);
emit reply->finishedWithError(errorCode, reply->d_func()->errorString);
+ int i = indexOf(socket);
// remove the corrupt data if any
reply->d_func()->eraseData();
@@ -366,8 +358,7 @@ void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket,
channels[i].close();
channels[i].reply = 0;
channels[i].request = QHttpNetworkRequest();
- if (socket)
- channels[i].requeueCurrentlyPipelinedRequests();
+ channels[i].requeueCurrentlyPipelinedRequests();
// send the next request
QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
@@ -591,9 +582,9 @@ void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair)
bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket)
{
- int i = 0;
- if (socket)
- i = indexOf(socket);
+ Q_ASSERT(socket);
+
+ int i = indexOf(socket);
if (!highPriorityQueue.isEmpty()) {
// remove from queue before sendRequest! else we might pipeline the same request again
@@ -749,15 +740,15 @@ bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue,
}
-QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, const QString &extraDetail)
+QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket* socket,
+ const QString &extraDetail)
{
+ Q_ASSERT(socket);
+
QString errorString;
switch (errorCode) {
case QNetworkReply::HostNotFoundError:
- if (socket)
- errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());
- else
- errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName);
+ errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());
break;
case QNetworkReply::ConnectionRefusedError:
errorString = QCoreApplication::translate("QHttp", "Connection refused");
@@ -900,11 +891,9 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
return;
// try to get a free AND connected socket
for (int i = 0; i < channelCount; ++i) {
- if (channels[i].socket) {
- if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
- if (dequeueRequest(channels[i].socket))
- channels[i].sendRequest();
- }
+ if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
+ if (dequeueRequest(channels[i].socket))
+ channels[i].sendRequest();
}
}
@@ -919,7 +908,7 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
return;
for (int i = 0; i < channelCount; i++)
- if (channels[i].socket && channels[i].socket->state() == QAbstractSocket::ConnectedState)
+ if (channels[i].socket->state() == QAbstractSocket::ConnectedState)
fillPipeline(channels[i].socket);
// If there is not already any connected channels we need to connect a new one.
@@ -927,19 +916,11 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
// connected or not. This is to reuse connected channels before we connect new once.
int queuedRequest = highPriorityQueue.count() + lowPriorityQueue.count();
for (int i = 0; i < channelCount; ++i) {
- bool connectChannel = false;
- if (channels[i].socket) {
- if ((channels[i].socket->state() == QAbstractSocket::ConnectingState) || (channels[i].socket->state() == QAbstractSocket::HostLookupState))
- queuedRequest--;
- if ( queuedRequest <=0 )
- break;
- if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState))
- connectChannel = true;
- } else { // not previously used channel
- connectChannel = true;
- }
-
- if (connectChannel) {
+ if ((channels[i].socket->state() == QAbstractSocket::ConnectingState) || (channels[i].socket->state() == QAbstractSocket::HostLookupState))
+ queuedRequest--;
+ if ( queuedRequest <=0 )
+ break;
+ if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState)) {
if (networkLayerState == IPv4)
channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol;
else if (networkLayerState == IPv6)
@@ -947,9 +928,6 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest()
channels[i].ensureConnection();
queuedRequest--;
}
-
- if ( queuedRequest <=0 )
- break;
}
}
@@ -980,8 +958,8 @@ void QHttpNetworkConnectionPrivate::startHostInfoLookup()
#ifndef QT_NO_NETWORKPROXY
if (networkProxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
lookupHost = networkProxy.hostName();
- } else if (channels[0].proxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
- lookupHost = channels[0].proxy.hostName();
+ } else if (channels[0].socket->proxy().capabilities() & QNetworkProxy::HostNameLookupCapability) {
+ lookupHost = channels[0].socket->proxy().hostName();
}
#endif
QHostAddress temp;
@@ -1191,7 +1169,7 @@ void QHttpNetworkConnection::setTransparentProxy(const QNetworkProxy &networkPro
{
Q_D(QHttpNetworkConnection);
for (int i = 0; i < d->channelCount; ++i)
- d->channels[i].setProxy(networkProxy);
+ d->channels[i].socket->setProxy(networkProxy);
}
QNetworkProxy QHttpNetworkConnection::transparentProxy() const
@@ -1212,7 +1190,7 @@ void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config
// set the config on all channels
for (int i = 0; i < d->channelCount; ++i)
- d->channels[i].setSslConfiguration(config);
+ static_cast<QSslSocket *>(d->channels[i].socket)->setSslConfiguration(config);
}
void QHttpNetworkConnection::ignoreSslErrors(int channel)
@@ -1223,11 +1201,13 @@ void QHttpNetworkConnection::ignoreSslErrors(int channel)
if (channel == -1) { // ignore for all channels
for (int i = 0; i < d->channelCount; ++i) {
- d->channels[i].ignoreSslErrors();
+ static_cast<QSslSocket *>(d->channels[i].socket)->ignoreSslErrors();
+ d->channels[i].ignoreAllSslErrors = true;
}
} else {
- d->channels[channel].ignoreSslErrors();
+ static_cast<QSslSocket *>(d->channels[channel].socket)->ignoreSslErrors();
+ d->channels[channel].ignoreAllSslErrors = true;
}
}
@@ -1239,11 +1219,13 @@ void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int
if (channel == -1) { // ignore for all channels
for (int i = 0; i < d->channelCount; ++i) {
- d->channels[i].ignoreSslErrors(errors);
+ static_cast<QSslSocket *>(d->channels[i].socket)->ignoreSslErrors(errors);
+ d->channels[i].ignoreSslErrorsList = errors;
}
} else {
- d->channels[channel].ignoreSslErrors(errors);
+ static_cast<QSslSocket *>(d->channels[channel].socket)->ignoreSslErrors(errors);
+ d->channels[channel].ignoreSslErrorsList = errors;
}
}
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index a009222bd5..3991bffa47 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -65,7 +65,6 @@ QT_BEGIN_NAMESPACE
QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
: socket(0)
, ssl(false)
- , isInitialized(false)
, state(IdleState)
, reply(0)
, written(0)
@@ -153,38 +152,19 @@ void QHttpNetworkConnectionChannel::init()
QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)),
this, SLOT(_q_encryptedBytesWritten(qint64)),
Qt::DirectConnection);
-
- if (ignoreAllSslErrors)
- sslSocket->ignoreSslErrors();
-
- if (!ignoreSslErrorsList.isEmpty())
- sslSocket->ignoreSslErrors(ignoreSslErrorsList);
-
- if (!sslConfiguration.isNull())
- sslSocket->setSslConfiguration(sslConfiguration);
}
-
#endif
-
-#ifndef QT_NO_NETWORKPROXY
- if (proxy.type() != QNetworkProxy::NoProxy)
- socket->setProxy(proxy);
-#endif
- isInitialized = true;
}
void QHttpNetworkConnectionChannel::close()
{
- if (!socket)
- state = QHttpNetworkConnectionChannel::IdleState;
- else if (socket->state() == QAbstractSocket::UnconnectedState)
+ if (socket->state() == QAbstractSocket::UnconnectedState)
state = QHttpNetworkConnectionChannel::IdleState;
else
state = QHttpNetworkConnectionChannel::ClosingState;
- if (socket)
- socket->close();
+ socket->close();
}
@@ -547,9 +527,6 @@ void QHttpNetworkConnectionChannel::handleUnexpectedEOF()
bool QHttpNetworkConnectionChannel::ensureConnection()
{
- if (!isInitialized)
- init();
-
QAbstractSocket::SocketState socketState = socket->state();
// resend this request after we receive the disconnected signal
@@ -858,46 +835,6 @@ bool QHttpNetworkConnectionChannel::resetUploadData()
}
}
-#ifndef QT_NO_NETWORKPROXY
-
-void QHttpNetworkConnectionChannel::setProxy(const QNetworkProxy &networkProxy)
-{
- if (socket)
- socket->setProxy(networkProxy);
-
- proxy = networkProxy;
-}
-
-#endif
-
-#ifndef QT_NO_SSL
-
-void QHttpNetworkConnectionChannel::ignoreSslErrors()
-{
- if (socket)
- static_cast<QSslSocket *>(socket)->ignoreSslErrors();
-
- ignoreAllSslErrors = true;
-}
-
-
-void QHttpNetworkConnectionChannel::ignoreSslErrors(const QList<QSslError> &errors)
-{
- if (socket)
- static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors);
-
- ignoreSslErrorsList = errors;
-}
-
-void QHttpNetworkConnectionChannel::setSslConfiguration(const QSslConfiguration &config)
-{
- if (socket)
- static_cast<QSslSocket *>(socket)->setSslConfiguration(config);
-
- sslConfiguration = config;
-}
-
-#endif
void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair)
{
diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h
index 2648cba2a5..7da9b514d6 100644
--- a/src/network/access/qhttpnetworkconnectionchannel_p.h
+++ b/src/network/access/qhttpnetworkconnectionchannel_p.h
@@ -72,7 +72,6 @@
#ifndef QT_NO_SSL
# include <QtNetwork/qsslsocket.h>
# include <QtNetwork/qsslerror.h>
-# include <QtNetwork/qsslconfiguration.h>
#else
# include <QtNetwork/qtcpsocket.h>
#endif
@@ -101,7 +100,6 @@ public:
};
QAbstractSocket *socket;
bool ssl;
- bool isInitialized;
ChannelState state;
QHttpNetworkRequest request; // current request
QHttpNetworkReply *reply; // current reply for this request
@@ -120,10 +118,6 @@ public:
#ifndef QT_NO_SSL
bool ignoreAllSslErrors;
QList<QSslError> ignoreSslErrorsList;
- QSslConfiguration sslConfiguration;
- void ignoreSslErrors();
- void ignoreSslErrors(const QList<QSslError> &errors);
- void setSslConfiguration(const QSslConfiguration &config);
#endif
#ifndef QT_NO_BEARERMANAGEMENT
QSharedPointer<QNetworkSession> networkSession;
@@ -150,11 +144,6 @@ public:
void setConnection(QHttpNetworkConnection *c);
QPointer<QHttpNetworkConnection> connection;
-#ifndef QT_NO_NETWORKPROXY
- QNetworkProxy proxy;
- void setProxy(const QNetworkProxy &networkProxy);
-#endif
-
void init();
void close();