[PATCH] Improve wifi scanning throttling code



From: Sjoerd Simons <sjoerd simons collabora co uk>

Throttle requesting scan results to be at least four seconds, instead
of always forcing a 4 second delay after the first scan.
---
 src/supplicant-manager/nm-supplicant-interface.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

For master branch

diff --git a/src/supplicant-manager/nm-supplicant-interface.c b/src/supplicant-manager/nm-supplicant-interface.c
index 636005e..00f0c30 100644
--- a/src/supplicant-manager/nm-supplicant-interface.c
+++ b/src/supplicant-manager/nm-supplicant-interface.c
@@ -597,15 +597,23 @@ static void
 wpas_iface_query_scan_results (DBusGProxy *proxy, gpointer user_data)
 {
 	NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (user_data);
+	GTimeVal cur_time;
 
 	/* Only query scan results if a query is not queued */
 	if (priv->scan_results_timeout)
 		return;
 
+	g_get_current_time (&cur_time);
+
 	/* Only fetch scan results every 4s max, but initially do it right away */
-	priv->scan_results_timeout = g_timeout_add_seconds (priv->last_scan ? 4 : 0,
-	                                                    request_scan_results,
-	                                                    user_data);
+	if (priv->last_scan + 4 < cur_time.tv_sec) {
+		priv->scan_results_timeout = g_idle_add (request_scan_results,
+		                                         user_data);
+	} else {
+		priv->scan_results_timeout =
+			g_timeout_add_seconds ((4 - (cur_time.tv_sec - priv->last_scan)),
+			               request_scan_results, user_data);
+	}
 }
 
 static guint32
-- 
1.6.2.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]