Diff between eb433ac16e88323cc2872c60becef38ee5f35f8f and 00e5127fbab7f22823cdfad8b5fbf467891af5df

Changed Files

File Additions Deletions Status
android/gatt.c +21 -2 modified

Full Patch

diff --git a/android/gatt.c b/android/gatt.c
index 0a8684e..d63efc9 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -68,6 +68,8 @@
 #define GATT_PERM_WRITE_SIGNED		0x00010000
 #define GATT_PERM_WRITE_SIGNED_MITM	0x00020000
 
+#define GATT_CONN_TIMEOUT 2
+
 static const uint8_t BLUETOOTH_UUID[] = {
 	0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
 	0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -169,6 +171,8 @@ struct app_connection {
 	struct queue *transactions;
 	int32_t id;
 
+	guint timeout_id;
+
 	bool wait_execute_write;
 };
 
@@ -832,6 +836,9 @@ static void destroy_connection(void *data)
 {
 	struct app_connection *conn = data;
 
+	if (conn->timeout_id > 0)
+		g_source_remove(conn->timeout_id);
+
 	if (!queue_find(gatt_devices, match_by_value, conn->device))
 		goto cleanup;
 
@@ -1213,6 +1220,17 @@ reply:
 	send_client_search_complete_notify(gatt_status, cb_data->conn->id);
 	free(cb_data);
 }
+static gboolean connection_timeout(void *user_data)
+{
+	struct app_connection *conn = user_data;
+
+	conn->timeout_id = 0;
+
+	queue_remove(app_connections, conn);
+	destroy_connection(conn);
+
+	return FALSE;
+}
 
 static void discover_primary_cb(uint8_t status, GSList *services,
 								void *user_data)
@@ -1255,8 +1273,9 @@ static void discover_primary_cb(uint8_t status, GSList *services,
 	bt_device_set_uuids(&dev->bdaddr, uuids);
 
 	free(cb_data);
-	queue_remove(app_connections, conn);
-	destroy_connection(conn);
+
+	conn->timeout_id = g_timeout_add_seconds(GATT_CONN_TIMEOUT,
+						connection_timeout, conn);
 }
 
 static guint search_dev_for_srvc(struct app_connection *conn, bt_uuid_t *uuid)