//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()));
}
// 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);
+ }
}
}
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
QNetworkReply::NetworkError errorCode)
{
Q_Q(QHttpNetworkConnection);
- if (socket && reply) {
+
+ int i = 0;
+ if (socket)
+ i = indexOf(socket);
+
+ if (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();
channels[i].close();
channels[i].reply = 0;
channels[i].request = QHttpNetworkRequest();
- channels[i].requeueCurrentlyPipelinedRequests();
+ if (socket)
+ channels[i].requeueCurrentlyPipelinedRequests();
// send the next request
QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket)
{
- Q_ASSERT(socket);
-
- int i = indexOf(socket);
+ int i = 0;
+ if (socket)
+ i = indexOf(socket);
if (!highPriorityQueue.isEmpty()) {
// remove from queue before sendRequest! else we might pipeline the same request again
}
-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:
- errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());
+ if (socket)
+ errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());
+ else
+ errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName);
break;
case QNetworkReply::ConnectionRefusedError:
errorString = QCoreApplication::translate("QHttp", "Connection refused");
return;
// try to get a free AND connected socket
for (int i = 0; i < channelCount; ++i) {
- if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
- if (dequeueRequest(channels[i].socket))
- channels[i].sendRequest();
+ 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 (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
return;
for (int i = 0; i < channelCount; i++)
- if (channels[i].socket->state() == QAbstractSocket::ConnectedState)
+ if (channels[i].socket && 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.
// 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) {
- 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)) {
+ 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 (networkLayerState == IPv4)
channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol;
else if (networkLayerState == IPv6)
channels[i].ensureConnection();
queuedRequest--;
}
+
+ if ( queuedRequest <=0 )
+ break;
}
}
#ifndef QT_NO_NETWORKPROXY
if (networkProxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
lookupHost = networkProxy.hostName();
- } else if (channels[0].socket->proxy().capabilities() & QNetworkProxy::HostNameLookupCapability) {
- lookupHost = channels[0].socket->proxy().hostName();
+ } else if (channels[0].proxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
+ lookupHost = channels[0].proxy.hostName();
}
#endif
QHostAddress temp;
{
Q_D(QHttpNetworkConnection);
for (int i = 0; i < d->channelCount; ++i)
- d->channels[i].socket->setProxy(networkProxy);
+ d->channels[i].setProxy(networkProxy);
}
QNetworkProxy QHttpNetworkConnection::transparentProxy() const
{
Q_D(const QHttpNetworkConnection);
- return d->channels[0].socket->proxy();
+ return d->channels[0].proxy;
}
#endif
// set the config on all channels
for (int i = 0; i < d->channelCount; ++i)
- static_cast<QSslSocket *>(d->channels[i].socket)->setSslConfiguration(config);
+ d->channels[i].setSslConfiguration(config);
}
void QHttpNetworkConnection::ignoreSslErrors(int channel)
if (channel == -1) { // ignore for all channels
for (int i = 0; i < d->channelCount; ++i) {
- static_cast<QSslSocket *>(d->channels[i].socket)->ignoreSslErrors();
- d->channels[i].ignoreAllSslErrors = true;
+ d->channels[i].ignoreSslErrors();
}
} else {
- static_cast<QSslSocket *>(d->channels[channel].socket)->ignoreSslErrors();
- d->channels[channel].ignoreAllSslErrors = true;
+ d->channels[channel].ignoreSslErrors();
}
}
if (channel == -1) { // ignore for all channels
for (int i = 0; i < d->channelCount; ++i) {
- static_cast<QSslSocket *>(d->channels[i].socket)->ignoreSslErrors(errors);
- d->channels[i].ignoreSslErrorsList = errors;
+ d->channels[i].ignoreSslErrors(errors);
}
} else {
- static_cast<QSslSocket *>(d->channels[channel].socket)->ignoreSslErrors(errors);
- d->channels[channel].ignoreSslErrorsList = errors;
+ d->channels[channel].ignoreSslErrors(errors);
}
}
QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel()
: socket(0)
, ssl(false)
+ , isInitialized(false)
, state(IdleState)
, reply(0)
, written(0)
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() == QAbstractSocket::UnconnectedState)
+ if (!socket)
+ state = QHttpNetworkConnectionChannel::IdleState;
+ else if (socket->state() == QAbstractSocket::UnconnectedState)
state = QHttpNetworkConnectionChannel::IdleState;
else
state = QHttpNetworkConnectionChannel::ClosingState;
- socket->close();
+ if (socket)
+ socket->close();
}
bool QHttpNetworkConnectionChannel::ensureConnection()
{
+ if (!isInitialized)
+ init();
+
QAbstractSocket::SocketState socketState = socket->state();
// resend this request after we receive the disconnected signal
}
}
+#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)
{