summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-04-29 14:45:26 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-04-30 14:48:56 +0000
commit382577419a80a8aebaa7ac95682cdec46a487ace (patch)
treecbe6acbe6c2c2d0983aadd687fdb414e2fb7314a
parentebc3350be7b67f6cc8ca7cf30cefd98e88b87ef5 (diff)
QNAM/QNetConMon: Update handling of QNetworkConnectionMonitor::start
QNetworkConnectionMonitor::start was previously called after checking d->networkAccessible, unfortunately that means if the network was unavailable when QNetworkConnectionMonitor was created we don't subscribe to updates or recheck the status (unless QNetworkAccessManager::networkAccessible() is called). Move the call to start to before the offline check. Also update the Windows backend so that it updates networkAccessible on the call to start() Pick-to: 5.15 Change-Id: I37647f19f703947143e7cbdafe09619ce0d98cc1 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp11
-rw-r--r--src/network/kernel/qnetconmonitor_win.cpp8
2 files changed, 14 insertions, 5 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 63a816b9dc..e5414665de 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -1248,10 +1248,14 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
}
if (d->statusMonitor.isEnabled()) {
+ if (!d->statusMonitor.isMonitoring() && !d->statusMonitor.start())
+ qWarning(lcNetMon, "failed to start network status monitoring");
+
// See the code in ctor - QNetworkStatusMonitor allows us to
// immediately set 'networkAccessible' even before we start
- // the monitor.
- if (!d->networkAccessible && !isLocalFile) {
+ // the monitor. If the monitor is unable to monitor then let's
+ // assume there's something wrong with the monitor and keep going.
+ if (d->statusMonitor.isMonitoring() && !d->networkAccessible && !isLocalFile) {
QHostAddress dest;
QString host = req.url().host().toLower();
if (!(dest.setAddress(host) && dest.isLoopback())
@@ -1260,9 +1264,6 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
return new QDisabledNetworkReply(this, req, op);
}
}
-
- if (!d->statusMonitor.isMonitoring() && !d->statusMonitor.start())
- qWarning(lcNetMon, "failed to start network status monitoring");
}
#endif
QNetworkRequest request = req;
diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp
index 59b6cd5b66..b8cf23529a 100644
--- a/src/network/kernel/qnetconmonitor_win.cpp
+++ b/src/network/kernel/qnetconmonitor_win.cpp
@@ -618,6 +618,14 @@ bool QNetworkListManagerEvents::start()
<< errorStringFromHResult(hr);
return false;
}
+
+ // Update connectivity since it might have changed since this class was constructed
+ NLM_CONNECTIVITY connectivity;
+ hr = networkListManager->GetConnectivity(&connectivity);
+ if (FAILED(hr))
+ qCWarning(lcNetMon) << "Could not get connectivity:" << errorStringFromHResult(hr);
+ else
+ monitor->setConnectivity(connectivity);
return true;
}