Skip to content

Commit

Permalink
notifyWait added
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Apr 1, 2024
1 parent b591a97 commit f051b99
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Network/NetworkConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ namespace WPEFramework {
if (isMonitorThreadRunning())
{
LOGINFO("Connectivity Monitor Thread is active so notify");
resetConnectivityCache();
cv_.notify_all();
}
else
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f051b99

Please sign in to comment.