Skip to content

Commit

Permalink
QNetworkStatusMonitor - make it always enabled on Darwin
Browse files Browse the repository at this point in the history
Also undo changes in setNetworkAccessible and setConfiguration
since they introduced a change in behavior, which results
in auto-test failing.

Change-Id: I5d74c47338bff8f964ba2e27256902c79303e00f
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
Timur Pocheptsov committed May 10, 2019
1 parent 681bd76 commit 8ac7712
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
16 changes: 4 additions & 12 deletions src/network/access/qnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,10 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ
void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config)
{
Q_D(QNetworkAccessManager);
if (!d->statusMonitor.isEnabled()) {
d->networkConfiguration = config;
d->customNetworkConfiguration = true;
d->createSession(config);
} else {
qWarning(lcNetMon, "No network configuration can be set with network status monitor enabled");
}

d->networkConfiguration = config;
d->customNetworkConfiguration = true;
d->createSession(config);
}

/*!
Expand Down Expand Up @@ -1107,11 +1104,6 @@ void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkA
{
Q_D(QNetworkAccessManager);

if (d->statusMonitor.isEnabled()) {
qWarning(lcNetMon, "Can not manually set network accessibility with the network status monitor enabled");
return;
}

d->defaultAccessControl = accessible == NotAccessible ? false : true;

if (d->networkAccessible != accessible) {
Expand Down
17 changes: 1 addition & 16 deletions src/network/kernel/qnetconmonitor_darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <netinet/in.h>

#include <cstring>
#include <mutex>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -309,20 +308,8 @@ qt_sockaddr qt_hostaddress_to_sockaddr(const QHostAddress &src)
bool isOnlineIpv4 = false;
QNetworkConnectionMonitor ipv6Probe;
bool isOnlineIpv6 = false;

static bool enabled;
static void readEnv();
};

bool QNetworkStatusMonitorPrivate::enabled = false;

void QNetworkStatusMonitorPrivate::readEnv()
{
bool envOk = false;
const int env = qEnvironmentVariableIntValue("QT_USE_NETWORK_MONITOR", &envOk);
enabled = envOk && env > 0;
}

QNetworkStatusMonitor::QNetworkStatusMonitor()
: QObject(*new QNetworkStatusMonitorPrivate)
{
Expand Down Expand Up @@ -400,9 +387,7 @@ qt_sockaddr qt_hostaddress_to_sockaddr(const QHostAddress &src)

bool QNetworkStatusMonitor::isEnabled()
{
static std::once_flag envRead = {};
std::call_once(envRead, QNetworkStatusMonitorPrivate::readEnv);
return QNetworkStatusMonitorPrivate::enabled;
return true;
}

void QNetworkStatusMonitor::reachabilityChanged(bool online)
Expand Down

0 comments on commit 8ac7712

Please sign in to comment.