diff --git a/networkdetector/devicemonitor.cpp b/networkdetector/devicemonitor.cpp index 7c0eaed0..dfc54c6f 100644 --- a/networkdetector/devicemonitor.cpp +++ b/networkdetector/devicemonitor.cpp @@ -27,6 +27,10 @@ DeviceMonitor::~DeviceMonitor() void DeviceMonitor::update() { + if (m_pingProcess->state() != QProcess::NotRunning) { + qCDebug(dcNetworkDetector()) << "Previous ping still running for device" << m_host->address() << ". Not updating."; + return; + } lookupArpCache(); } @@ -50,9 +54,14 @@ void DeviceMonitor::ping() } if (!targetInterface.isValid()) { qCWarning(dcNetworkDetector()) << "Could not find a suitable interface to ping for" << m_host->address(); + if (m_host->reachable()) { + m_host->setReachable(false); + emit reachableChanged(false); + } return; } - m_pingProcess->start("arping", {"-I", targetInterface.name(), "-f", "-w", "5", m_host->address()}); + + m_pingProcess->start("arping", {"-I", targetInterface.name(), "-f", "-w", "90", m_host->address()}); } void DeviceMonitor::arpLookupFinished(int exitCode) @@ -95,12 +104,6 @@ void DeviceMonitor::arpLookupFinished(int exitCode) qCDebug(dcNetworkDetector()) << "Device" << m_host->macAddress() << "not found in ARP cache. Trying to ping it on" << m_host->address(); ping(); } - - if (m_host->reachable() && m_host->lastSeenTime().addSecs(20) < QDateTime::currentDateTime()) { - qCDebug(dcNetworkDetector()) << "Could not reach device for 20 seconds. Marking it as gone." << m_host->address() << m_host->macAddress(); - m_host->setReachable(false); - emit reachableChanged(false); - } } void DeviceMonitor::pingFinished(int exitCode) @@ -116,6 +119,10 @@ void DeviceMonitor::pingFinished(int exitCode) emit seen(); } else { qCDebug(dcNetworkDetector()) << "Could not ping device" << m_host->macAddress() << m_host->address(); + if (m_host->reachable()) { + m_host->setReachable(false); + emit reachableChanged(false); + } } // read data to discard it from socket QString data = QString::fromLatin1(m_pingProcess->readAll()); diff --git a/networkdetector/devicepluginnetworkdetector.cpp b/networkdetector/devicepluginnetworkdetector.cpp index 7556e7b0..605bba18 100644 --- a/networkdetector/devicepluginnetworkdetector.cpp +++ b/networkdetector/devicepluginnetworkdetector.cpp @@ -82,6 +82,7 @@ DeviceManager::DeviceSetupStatus DevicePluginNetworkDetector::setupDevice(Device connect(monitor, &DeviceMonitor::addressChanged, this, &DevicePluginNetworkDetector::deviceAddressChanged); connect(monitor, &DeviceMonitor::seen, this, &DevicePluginNetworkDetector::deviceSeen); m_monitors.insert(monitor, device); + monitor->update(); return DeviceManager::DeviceSetupStatusSuccess; } diff --git a/networkdetector/devicepluginnetworkdetector.json b/networkdetector/devicepluginnetworkdetector.json index 4768567a..074b3caa 100644 --- a/networkdetector/devicepluginnetworkdetector.json +++ b/networkdetector/devicepluginnetworkdetector.json @@ -43,8 +43,7 @@ "displayName": "Device is present", "displayNameEvent": "Device is present changed", "type": "bool", - "defaultValue": false, - "cached": false + "defaultValue": false }, { "id": "b51d54c9-cce1-43f0-a35d-52fc2d8d302c",