device: Initial scan delays exponential backoff
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 18 Feb 2011 20:01:38 +0000 (21:01 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 18 Feb 2011 20:01:38 +0000 (21:01 +0100)
Scanning delays increase exponentially from 10 seconds to the scanning
interval, as long as the device network list is empty.

src/device.c

index 07c427de321cb012248c1e1d7d4f31100626f647..4822fa056bdc6439c8b158082af4a31239b77859 100644 (file)
@@ -40,6 +40,7 @@ struct connman_device {
        connman_bool_t disconnected;
        connman_bool_t reconnect;
        connman_uint16_t scan_interval;
+       connman_uint16_t backoff_interval;
        char *name;
        char *node;
        char *address;
@@ -57,6 +58,8 @@ struct connman_device {
        GHashTable *networks;
 };
 
+#define SCAN_INITIAL_DELAY 10
+
 static gboolean device_scan_trigger(gpointer user_data)
 {
        struct connman_device *device = user_data;
@@ -87,9 +90,23 @@ static void reset_scan_trigger(struct connman_device *device)
        clear_scan_trigger(device);
 
        if (device->scan_interval > 0) {
-               guint interval = device->scan_interval;
+               guint interval;
+
+               if (g_hash_table_size(device->networks) == 0) {
+                       if (device->backoff_interval >= device->scan_interval)
+                               device->backoff_interval = SCAN_INITIAL_DELAY;
+                       interval = device->backoff_interval;
+               } else
+                       interval = device->scan_interval;
+
+               DBG("interval %d", interval);
+
                device->scan_timeout = g_timeout_add_seconds(interval,
                                        device_scan_trigger, device);
+
+               device->backoff_interval *= 2;
+               if (device->backoff_interval > device->scan_interval)
+                       device->backoff_interval = device->scan_interval;
        }
 }
 
@@ -478,6 +495,7 @@ struct connman_device *connman_device_create(const char *node,
 
        service_type = __connman_device_get_service_type(device);
        device->blocked = __connman_technology_get_blocked(service_type);
+       device->backoff_interval = SCAN_INITIAL_DELAY;
 
        switch (type) {
        case CONNMAN_DEVICE_TYPE_UNKNOWN:
@@ -1021,6 +1039,9 @@ void __connman_device_decrease_connections(struct connman_device *device)
                return;
 
        device->connections--;
+
+       if (device->connections == 0)
+               device->backoff_interval = SCAN_INITIAL_DELAY;
 }
 
 /**