From f051b99c91ea3f54cae2d1e3f2b4c97ab5e18fc3 Mon Sep 17 00:00:00 2001 From: cmuhammedrafi Date: Mon, 1 Apr 2024 13:57:00 +0530 Subject: [PATCH] notifyWait added --- Network/NetworkConnectivity.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/Network/NetworkConnectivity.cpp b/Network/NetworkConnectivity.cpp index 1e0ca6605a..6935b2370e 100644 --- a/Network/NetworkConnectivity.cpp +++ b/Network/NetworkConnectivity.cpp @@ -493,6 +493,7 @@ namespace WPEFramework { if (isMonitorThreadRunning()) { LOGINFO("Connectivity Monitor Thread is active so notify"); + resetConnectivityCache(); cv_.notify_all(); } else @@ -568,32 +569,42 @@ namespace WPEFramework { void ConnectivityMonitor::connectivityMonitorFunction() { nsm_internetState InternetConnectionState = nsm_internetState::UNKNOWN; + int notifyWaitCount = 2; do { if(g_internetState.load() == nsm_internetState::FULLY_CONNECTED) - /*if previous check was fully connected then do connect only curl check*/ + /* If the previous check was fully connected, then perform only the curl check for connection. */ InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER, true); else - /*curl get request*/ + /* If not fully connected, use a curl GET request. */ InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER, false); if(g_internetState.load() != InternetConnectionState) { - g_internetState.store(InternetConnectionState); - Network::notifyInternetStatusChange(g_internetState.load()); + if(InternetConnectionState == NO_INTERNET && notifyWaitCount > 0) + { + /* Decrease the notification count to create a delay in posting the 'no internet' state. */ + notifyWaitCount--; + LOGINFO("notification count change to %d ...", notifyWaitCount); + } + else + { + g_internetState.store(InternetConnectionState); + Network::notifyInternetStatusChange(g_internetState.load()); + notifyWaitCount = 2; + LOGINFO("notification count change to %d ...", notifyWaitCount); + } } if(!isContinuesMonitoringNeeded && (g_internetState.load() == FULLY_CONNECTED)) { stopFlag = true; LOGINFO("Initial Connectivity Monitoring done Exiting ... FULLY_CONNECTED"); - threadRunning = false; break; } if(stopFlag) { - threadRunning = false; break; } //wait for next timout or conditon signal @@ -603,12 +614,15 @@ namespace WPEFramework { if(!stopFlag) { LOGINFO("Connectivity monitor received a trigger"); + /* If any IP or connection changes occur, it should result in a 'no internet' state. Therefore, post the notification immediately. */ + notifyWaitCount = -1; } } - } while (!stopFlag); - g_internetState = nsm_internetState::UNKNOWN; + LOGWARN("Connectivity monitor exiting"); + g_internetState = nsm_internetState::UNKNOWN; + threadRunning = false; } } // namespace Plugin