tst_QUdpSocket: move up the search for IPv6-capable interfaces
Let's do it in initTestCase(), where we're already searching for IPv6 addresses, instead of storing the information in a local static. Pick-to: 6.6 Change-Id: Ifa1111900d6945ea8e05fffd177efb6a055aaa58 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
2e51fbf89a
commit
fd924ab0b6
@ -122,6 +122,7 @@ private:
|
|||||||
QList<QHostAddress> allAddresses;
|
QList<QHostAddress> allAddresses;
|
||||||
QHostAddress multicastGroup4, multicastGroup6;
|
QHostAddress multicastGroup4, multicastGroup6;
|
||||||
QList<QHostAddress> linklocalMulticastGroups;
|
QList<QHostAddress> linklocalMulticastGroups;
|
||||||
|
QNetworkInterface ifaceWithIPv6;
|
||||||
QUdpSocket *m_asyncSender;
|
QUdpSocket *m_asyncSender;
|
||||||
QUdpSocket *m_asyncReceiver;
|
QUdpSocket *m_asyncReceiver;
|
||||||
};
|
};
|
||||||
@ -172,26 +173,7 @@ QNetworkInterface tst_QUdpSocket::interfaceForGroup(const QHostAddress &multicas
|
|||||||
if (!scope.isEmpty())
|
if (!scope.isEmpty())
|
||||||
return QNetworkInterface::interfaceFromName(scope);
|
return QNetworkInterface::interfaceFromName(scope);
|
||||||
|
|
||||||
static QNetworkInterface ipv6if = [&]() {
|
return ifaceWithIPv6;
|
||||||
// find any link local address in the allAddress list
|
|
||||||
for (const QHostAddress &addr: std::as_const(allAddresses)) {
|
|
||||||
if (addr.isLoopback())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
QString scope = addr.scopeId();
|
|
||||||
if (!scope.isEmpty()) {
|
|
||||||
QNetworkInterface iface = QNetworkInterface::interfaceFromName(scope);
|
|
||||||
qDebug() << "Will bind IPv6 sockets to" << iface;
|
|
||||||
return iface;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qWarning("interfaceForGroup(%s) could not find any link-local IPv6 address! "
|
|
||||||
"Make sure this test is behind a check of QtNetworkSettings::hasIPv6().",
|
|
||||||
qUtf8Printable(multicastGroup.toString()));
|
|
||||||
return QNetworkInterface();
|
|
||||||
}();
|
|
||||||
return ipv6if;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tst_QUdpSocket::shouldWorkaroundLinuxKernelBug()
|
bool tst_QUdpSocket::shouldWorkaroundLinuxKernelBug()
|
||||||
@ -276,9 +258,16 @@ void tst_QUdpSocket::initTestCase()
|
|||||||
continue;
|
continue;
|
||||||
llbase.setScopeId(scope);
|
llbase.setScopeId(scope);
|
||||||
linklocalMulticastGroups << llbase;
|
linklocalMulticastGroups << llbase;
|
||||||
|
if (!ifaceWithIPv6.isValid()) {
|
||||||
|
// Remember the first interface we've found that has IPv6 so we can
|
||||||
|
// bind non-link-local sockets to it (the first is least likely to
|
||||||
|
// be some weird virtual interface).
|
||||||
|
ifaceWithIPv6 = QNetworkInterface::interfaceFromName(scope);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups;
|
qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups;
|
||||||
|
qDebug() << "Will bind IPv6 sockets to" << ifaceWithIPv6;
|
||||||
|
|
||||||
m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug();
|
m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug();
|
||||||
if (QTestPrivate::isRunningArmOnX86())
|
if (QTestPrivate::isRunningArmOnX86())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user