Throttle requesting scan results to be at least four seconds, instead of always
forcing a 4 second delay after the first scan.

Also Only emit SCAN_RESULT when the supplicant signalled this over dbus or when
the scan request failed.

Signed-off-by: Sjoerd Simons <[EMAIL PROTECTED]>
---
 src/supplicant-manager/nm-supplicant-interface.c |   27 ++++++++++++++-------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/supplicant-manager/nm-supplicant-interface.c 
b/src/supplicant-manager/nm-supplicant-interface.c
index 43cd167..cb98a39 100644
--- a/src/supplicant-manager/nm-supplicant-interface.c
+++ b/src/supplicant-manager/nm-supplicant-interface.c
@@ -573,15 +573,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 (priv->last_scan ? 4000 : 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 ((4 - (cur_time.tv_sec - 
priv->last_scan)) * 1000,
+                                      request_scan_results, user_data);
+       }
 }
 
 static guint32
@@ -1225,13 +1233,14 @@ scan_request_cb (DBusGProxy *proxy, DBusGProxyCall 
*call_id, gpointer user_data)
                                                                
G_TYPE_INVALID)) {
                nm_warning  ("Could not get scan request result: %s", 
err->message);
                g_error_free (err);
-       } 
+       }
 
-       /* Notify listeners of the result of the scan */
-       g_signal_emit (info->interface,
-                      nm_supplicant_interface_signals[SCAN_RESULT],
-                      0,
-                                  success ? TRUE : FALSE);
+       /* Notify listeners if the scan failed */
+       if (!success) {
+               g_signal_emit (info->interface,
+                       nm_supplicant_interface_signals[SCAN_RESULT],
+                       0, FALSE);
+       }
 }
 
 gboolean
-- 
1.5.6.3

_______________________________________________
NetworkManager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to