From 382577419a80a8aebaa7ac95682cdec46a487ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 29 Apr 2020 14:45:26 +0200 Subject: 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 --- src/network/access/qnetworkaccessmanager.cpp | 11 ++++++----- src/network/kernel/qnetconmonitor_win.cpp | 8 ++++++++ 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; } -- cgit v1.2.3