Commit 66b8f2b7 authored by Dan Winship's avatar Dan Winship

connectivity: avoid redundant connectivity checks

Don't start an automatic connectivity check right when NMManager tells
us we're online; only do it if the manager doesn't request an explicit
connectivity check immediately afterward.
parent 0997c4b2
...@@ -44,7 +44,7 @@ typedef struct { ...@@ -44,7 +44,7 @@ typedef struct {
#if WITH_CONCHECK #if WITH_CONCHECK
SoupSession *soup_session; SoupSession *soup_session;
gboolean running; guint pending_checks;
guint check_id; guint check_id;
#endif #endif
...@@ -114,6 +114,7 @@ nm_connectivity_check_cb (SoupSession *session, SoupMessage *msg, gpointer user_ ...@@ -114,6 +114,7 @@ nm_connectivity_check_cb (SoupSession *session, SoupMessage *msg, gpointer user_
self = NM_CONNECTIVITY (g_async_result_get_source_object (G_ASYNC_RESULT (simple))); self = NM_CONNECTIVITY (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
g_object_unref (self); g_object_unref (self);
priv = NM_CONNECTIVITY_GET_PRIVATE (self); priv = NM_CONNECTIVITY_GET_PRIVATE (self);
priv->pending_checks--;
if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) { if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
nm_log_info (LOGD_CONCHECK, "Connectivity check for uri '%s' failed with '%s'.", nm_log_info (LOGD_CONCHECK, "Connectivity check for uri '%s' failed with '%s'.",
...@@ -157,11 +158,9 @@ run_check_complete (GObject *object, ...@@ -157,11 +158,9 @@ run_check_complete (GObject *object,
gpointer user_data) gpointer user_data)
{ {
NMConnectivity *self = NM_CONNECTIVITY (object); NMConnectivity *self = NM_CONNECTIVITY (object);
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
GError *error = NULL; GError *error = NULL;
nm_connectivity_check_finish (self, result, &error); nm_connectivity_check_finish (self, result, &error);
priv->running = FALSE;
if (error) { if (error) {
nm_log_err (LOGD_CONCHECK, "Connectivity check failed: %s", error->message); nm_log_err (LOGD_CONCHECK, "Connectivity check failed: %s", error->message);
g_error_free (error); g_error_free (error);
...@@ -172,13 +171,23 @@ static gboolean ...@@ -172,13 +171,23 @@ static gboolean
run_check (gpointer user_data) run_check (gpointer user_data)
{ {
NMConnectivity *self = NM_CONNECTIVITY (user_data); NMConnectivity *self = NM_CONNECTIVITY (user_data);
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
nm_connectivity_check_async (self, run_check_complete, NULL); nm_connectivity_check_async (self, run_check_complete, NULL);
priv->running = TRUE;
return TRUE; return TRUE;
} }
static gboolean
idle_start_periodic_checks (gpointer user_data)
{
NMConnectivity *self = user_data;
NMConnectivityPrivate *priv = NM_CONNECTIVITY_GET_PRIVATE (self);
priv->check_id = g_timeout_add_seconds (priv->interval, run_check, self);
if (!priv->pending_checks)
run_check (self);
return FALSE;
}
#endif #endif
void void
...@@ -194,9 +203,7 @@ nm_connectivity_set_online (NMConnectivity *self, ...@@ -194,9 +203,7 @@ nm_connectivity_set_online (NMConnectivity *self,
#if WITH_CONCHECK #if WITH_CONCHECK
if (online && priv->uri && priv->interval) { if (online && priv->uri && priv->interval) {
if (!priv->check_id) if (!priv->check_id)
priv->check_id = g_timeout_add_seconds (priv->interval, run_check, self); priv->check_id = g_timeout_add (0, idle_start_periodic_checks, self);
if (!priv->running)
run_check (self);
return; return;
} else if (priv->check_id) { } else if (priv->check_id) {
...@@ -241,6 +248,7 @@ nm_connectivity_check_async (NMConnectivity *self, ...@@ -241,6 +248,7 @@ nm_connectivity_check_async (NMConnectivity *self,
msg, msg,
nm_connectivity_check_cb, nm_connectivity_check_cb,
simple); simple);
priv->pending_checks++;
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment