From c5b742a5f69c0ef85bc0d56f1178692788eb5305 Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Wed, 6 Jun 2012 13:47:54 +0200 Subject: [PATCH] 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 --- src/network/access/qhttpnetworkconnection.cpp | 9 +++++++++ src/network/access/qhttpnetworkconnection_p.h | 1 + src/network/access/qhttpnetworkconnectionchannel.cpp | 1 + 3 files changed, 11 insertions(+) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 21802e4..6e56aa6 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -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) diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 1b9c703..74bf25a 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -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 diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 006f533..2971854 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -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))) { -- 2.7.4