mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
committed by
Mathew Sutcliffe
parent
98b2061d3d
commit
7faffc520d
@@ -574,17 +574,6 @@ namespace BlackCore
|
||||
return this->m_accessManager.networkAccessible() == QNetworkAccessManager::Accessible;
|
||||
}
|
||||
|
||||
bool CApplication::isNetworkConnected() const
|
||||
{
|
||||
static bool con = CNetworkUtils::hasConnectedInterface();
|
||||
return con;
|
||||
}
|
||||
|
||||
bool CApplication::isNetworkConnectedAndAccessible() const
|
||||
{
|
||||
return this->isNetworkConnected() && this->isNetworkAccessible();
|
||||
}
|
||||
|
||||
void CApplication::exit(int retcode)
|
||||
{
|
||||
if (instance())
|
||||
|
||||
@@ -154,12 +154,6 @@ namespace BlackCore
|
||||
//! Network accessible?
|
||||
bool isNetworkAccessible() const;
|
||||
|
||||
//! Network connected (at startup time)
|
||||
bool isNetworkConnected() const;
|
||||
|
||||
//! Network connected and also accessible
|
||||
bool isNetworkConnectedAndAccessible() const;
|
||||
|
||||
//! Setup already synchronized
|
||||
bool isSetupAvailable() const;
|
||||
|
||||
|
||||
@@ -48,30 +48,6 @@ namespace BlackMisc
|
||||
return 2000;
|
||||
}
|
||||
|
||||
bool CNetworkUtils::hasConnectedInterface(bool withDebugOutput)
|
||||
{
|
||||
// http://stackoverflow.com/questions/2475266/verfiying-the-network-connection-using-qt-4-4
|
||||
const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &interface : interfaces)
|
||||
{
|
||||
// details of connection
|
||||
if (withDebugOutput) qDebug() << "name:" << interface.name() << endl << "ip addresses:" << endl << "mac:" << interface.hardwareAddress() << endl;
|
||||
if (interface.flags().testFlag(QNetworkInterface::IsUp) && !interface.flags().testFlag(QNetworkInterface::IsLoopBack))
|
||||
{
|
||||
// this loop is important to check if there are addresses
|
||||
for (const QNetworkAddressEntry &entry : interface.addressEntries())
|
||||
{
|
||||
if (withDebugOutput) qDebug() << entry.ip().toString() << " / " << entry.netmask().toString() << endl;
|
||||
|
||||
// we have an interface that is up, and has an ip address, therefore the link is present
|
||||
// we will only enable this check on first positive, all later results are incorrect
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNetworkUtils::canPing(const QString &hostAddress)
|
||||
{
|
||||
if (hostAddress.isEmpty()) { return false; }
|
||||
@@ -110,12 +86,6 @@ namespace BlackMisc
|
||||
|
||||
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
||||
{
|
||||
if (!CNetworkUtils::hasConnectedInterface(false))
|
||||
{
|
||||
message = QObject::tr("No connected network interface", "BlackMisc");
|
||||
return false;
|
||||
}
|
||||
|
||||
// KB: I have had an issue with QTcpSocket. It was stuck in HostLookupState and did
|
||||
// only recover after a reboot for no obvious reason.
|
||||
// Currently trying the ping alternative
|
||||
|
||||
@@ -50,10 +50,6 @@ namespace BlackMisc
|
||||
//! Default for timeout
|
||||
static int getTimeoutMs();
|
||||
|
||||
//! Is a connected interface available?
|
||||
//! \param withDebugOutput enables some debugging output
|
||||
static bool hasConnectedInterface(bool withDebugOutput = false);
|
||||
|
||||
//! Can ping the address?
|
||||
//! \note uses OS ping
|
||||
static bool canPing(const QString &hostAddress);
|
||||
|
||||
Reference in New Issue
Block a user