diff options
author | Martin Petersson <martin.petersson@nokia.com> | 2011-08-24 17:24:21 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-30 13:01:59 +0200 |
commit | 13df02ad044cca3c0414f5e34c57fe04b69b414c (patch) | |
tree | 890a7b5691c23feb1be43e4a87fd6e706762663b /src | |
parent | 6f3e93e3cb90bb8551132880e0d158eaeb633c07 (diff) |
QHttpNetworkConnection : Fix the case when we only have one channel
For the Happy eyeballs implementation we use two channels for the case
where a host lookup gives us both Ipv4 and Ipv6 addresses.
In the case where the Connection is setup to only use one channel
we can not use this solution, so in this case we should use the old
way of connecting with one channel.
Task-number: QTBUG-20981
Change-Id: I6590fb4c67d6a8261cd0e4da8f99cd3603bbb524
Reviewed-on: http://codereview.qt.nokia.com/3524
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 71 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel.cpp | 6 |
2 files changed, 46 insertions, 31 deletions
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 0f1132e2a8..fc4eccc761 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -189,28 +189,35 @@ bool QHttpNetworkConnectionPrivate::shouldEmitChannelError(QAbstractSocket *sock int i = indexOf(socket); int otherSocket = (i == 0 ? 1 : 0); - if (networkLayerState == QHttpNetworkConnectionPrivate::InProgress) { - if (channels[otherSocket].isSocketBusy() && (channels[otherSocket].state != QHttpNetworkConnectionChannel::ClosingState)) { - // this was the first socket to fail. - channels[i].close(); - emitError = false; - } - else { - // Both connection attempts has failed. + if (channelCount == 1) { + if (networkLayerState == QHttpNetworkConnectionPrivate::InProgress) networkLayerState = QHttpNetworkConnectionPrivate::Unknown; - channels[i].close(); - emitError = true; - } + channels[0].close(); + emitError = true; } else { - if ((networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (channels[i].networkLayerPreference != QAbstractSocket::IPv4Protocol) - || (networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (channels[i].networkLayerPreference != QAbstractSocket::IPv6Protocol)) { - // First connection worked so this is the second one to complete and it failed. - channels[i].close(); - QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); - emitError = false; + if (networkLayerState == QHttpNetworkConnectionPrivate::InProgress) { + if (channels[otherSocket].isSocketBusy() && (channels[otherSocket].state != QHttpNetworkConnectionChannel::ClosingState)) { + // this was the first socket to fail. + channels[i].close(); + emitError = false; + } + else { + // Both connection attempts has failed. + networkLayerState = QHttpNetworkConnectionPrivate::Unknown; + channels[i].close(); + emitError = true; + } + } else { + if ((networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (channels[i].networkLayerPreference != QAbstractSocket::IPv4Protocol) + || (networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (channels[i].networkLayerPreference != QAbstractSocket::IPv6Protocol)) { + // First connection worked so this is the second one to complete and it failed. + channels[i].close(); + QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); + emitError = false; + } + if (networkLayerState == QHttpNetworkConnectionPrivate::Unknown) + qWarning() << "We got a connection error when networkLayerState is Unknown"; } - if (networkLayerState == QHttpNetworkConnectionPrivate::Unknown) - qWarning() << "We got a connection error when networkLayerState is Unknown"; } return emitError; } @@ -917,10 +924,6 @@ void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply) // lookup as then the hostinfo will already be in the cache. void QHttpNetworkConnectionPrivate::startHostInfoLookup() { - // At this time all channels should be unconnected. - Q_ASSERT(!channels[0].isSocketBusy()); - Q_ASSERT(!channels[1].isSocketBusy()); - networkLayerState = InProgress; // check if we already now can descide if this is IPv4 or IPv6 @@ -989,17 +992,23 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(QHostInfo info) // connection will then be disconnected. void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup() { - // At this time all channels should be unconnected. - Q_ASSERT(!channels[0].isSocketBusy()); - Q_ASSERT(!channels[1].isSocketBusy()); + if (channelCount > 1) { + // At this time all channels should be unconnected. + Q_ASSERT(!channels[0].isSocketBusy()); + Q_ASSERT(!channels[1].isSocketBusy()); - networkLayerState = InProgress; + networkLayerState = InProgress; - channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; - channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol; + channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; + channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol; - channels[0].ensureConnection(); // Possibly delay this one.. - channels[1].ensureConnection(); + channels[0].ensureConnection(); // Possibly delay this one.. + channels[1].ensureConnection(); + } else { + networkLayerState = InProgress; + channels[0].networkLayerPreference = QAbstractSocket::AnyIPProtocol; + channels[0].ensureConnection(); + } } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 8be876dd48..b1630c7b2b 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -955,6 +955,12 @@ void QHttpNetworkConnectionChannel::_q_connected() connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; else if (networkLayerPreference == QAbstractSocket::IPv6Protocol) connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; + else { + if (socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol) + connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; + else + connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; + } } else { if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol)) || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) { |