QtNetwork: disconnect other channels when network layer detected

With Happy Eyeballs we will connect one IPv4 and one IPv6 channel and
pick the network layer depending on which connects first. When the
first channel is connected we can close the other one.

Before this we let the other connection finish connecting and then
closed it. This will close the other one as soon as the first one
is connected.

Change-Id: Ib2ab3f949704fd39dc0584bd31b9bcaf75ce35f7
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
Martin Petersson 2012-06-06 13:47:54 +02:00 committed by Qt by Nokia
parent b002c7a8c0
commit c5b742a5f6
3 changed files with 11 additions and 0 deletions

View File

@ -1094,6 +1094,15 @@ void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup()
}
}
void QHttpNetworkConnectionPrivate::networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol)
{
for (int i = 0 ; i < channelCount; ++i) {
if ((channels[i].networkLayerPreference != protocol) && (channels[i].state == QHttpNetworkConnectionChannel::ConnectingState)) {
channels[i].close();
}
}
}
void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel()
{
if (delayIpv4)

View File

@ -193,6 +193,7 @@ public:
void startHostInfoLookup();
void startNetworkLayerStateLookup();
void networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol);
// private slots
void _q_startNextRequest(); // send the next request from the queue

View File

@ -1039,6 +1039,7 @@ void QHttpNetworkConnectionChannel::_q_connected()
else
connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6;
}
connection->d_func()->networkLayerDetected(networkLayerPreference);
} else {
if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol))
|| ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) {