summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2011-02-18 21:01:38 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2011-02-18 21:01:38 +0100
commit5beda15339a2d083e85ae6a9dab00595ad84cffc (patch)
tree95ee6913a95b691e9b3d1623662dfdba16f8c7b9
parente11862e9419c75bb44a18f2bf5752f94e6dbeb5b (diff)
downloadconnman-5beda15339a2d083e85ae6a9dab00595ad84cffc.tar.gz
connman-5beda15339a2d083e85ae6a9dab00595ad84cffc.tar.bz2
connman-5beda15339a2d083e85ae6a9dab00595ad84cffc.zip
device: Initial scan delays exponential backoff
Scanning delays increase exponentially from 10 seconds to the scanning interval, as long as the device network list is empty.
-rw-r--r--src/device.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/device.c b/src/device.c
index 07c427de..4822fa05 100644
--- a/src/device.c
+++ b/src/device.c
@@ -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;
}
/**