From 691ad351f74b5846c9cba2da29573fafd1e0f2cd Mon Sep 17 00:00:00 2001 From: Anderson Briglia Date: Tue, 4 Oct 2011 15:32:16 -0300 Subject: [PATCH] Enable re-connection if reason is Timeout The re-connection timer must be added just when the disconnection reason was "Connection timeout" for GATT based profiles. --- src/device.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index 0b45880eb..68d504dfb 100644 --- a/src/device.c +++ b/src/device.c @@ -1709,15 +1709,36 @@ static void att_connect_dispatched(gpointer user_data) device->auto_id = 0; } +static gboolean att_connect(gpointer user_data); + static void attrib_disconnected(gpointer user_data) { struct btd_device *device = user_data; + GIOChannel *io; + int sock, err = 0; + socklen_t len; + + io = g_attrib_get_channel(device->attrib); + sock = g_io_channel_unix_get_fd(io); + len = sizeof(err); + getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len); g_slist_foreach(device->attios, attio_disconnected, NULL); attrib_channel_detach(device->attachid); g_attrib_unref(device->attrib); device->attrib = NULL; + + if (device->auto_connect == FALSE) + return; + + if (err != ETIMEDOUT) + return; + + device->auto_id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT_IDLE, + AUTO_CONNECTION_INTERVAL, + att_connect, device, + att_connect_dispatched); } static void primary_cb(GSList *services, guint8 status, gpointer user_data) @@ -1773,8 +1794,6 @@ done: browse_request_free(req, shutdown); } -static gboolean att_connect(gpointer user_data); - static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) { struct btd_device *device = user_data; -- 2.47.3