Skip to content

Commit

Permalink
[qtbase] Check alternative connections when connecting. Contributes t…
Browse files Browse the repository at this point in the history
…o JB#47349

QNetworkAccessManager keeps track of a single connected session (e.g.
Wifi, mobile data) at a time. If the currently tracked session
disconnects, it checks whether any other network configuration is
online, and if so, it switches to make this the current session.

However, if the currently tracked session changes to the Connecting
state, QNetworkAccessManager will claim the network is inaccessible,
even if other configurations are online, and will refuse to switch to a
different session until the current session state changes from
Connecting to either Connected or Disconnected.

Unfortunately, occassionally Wifi connections will move into the
Connecting state and potentially not switch to the Connected or
Disconnected state for some time, which can block connectivity for apps
using QNetworkAccessManager to maintain connections (it's not clear
whether this is because the connection actually gets stuck, or because
the state change signals get lost somewhere; the result is the
same).

This change makes QNetworkAccessManager switch connection in case the
current session moves to the Connecting state while another online
configuration is available to use instead.
  • Loading branch information
llewelld committed Dec 1, 2019
1 parent 7a6bb23 commit 22410ac
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/network/access/qnetworkaccessmanager.cpp
Expand Up @@ -1651,19 +1651,14 @@ void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession
Q_Q(QNetworkAccessManager);
qCDebug(lcNetworkAccess) << "QNAM: network session state changed:" << state;

if ((state == QNetworkSession::Connecting) && (!getNetworkSession())) {
qCWarning(lcNetworkAccess) << "QNAM: ignoring Connecting state received after the session closed";
return;
}

bool reallyOnline = false;
//Do not emit the networkSessionConnected signal here, except for roaming -> connected
//transition, otherwise it is emitted twice in a row when opening a connection.
if (state == QNetworkSession::Connected && lastSessionState != QNetworkSession::Roaming)
emit q->networkSessionConnected();
lastSessionState = state;

if (state == QNetworkSession::Disconnected) {
if ((state == QNetworkSession::Disconnected) || (state == QNetworkSession::Connecting)) {
Q_FOREACH (const QNetworkConfiguration &cfg, networkConfigurationManager.allConfigurations()) {
if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
reallyOnline = true;
Expand Down

0 comments on commit 22410ac

Please sign in to comment.