Add the timeout to reset the pending info 23/309823/1
authorDohyun Pyun <dh79.pyun@samsung.com>
Fri, 29 Mar 2024 01:25:09 +0000 (10:25 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 17 Apr 2024 03:11:09 +0000 (12:11 +0900)
Change-Id: Id67b0f10b038c462dc8e9e2793f567da14c23a01

bt-service/services/socket/bt-service-socket.c

index ef772a7..998f41c 100644 (file)
 #include "bt-service-event.h"
 
 #define L2CAP_LE_UUID_SUBSTR "FFFFFFFF-FFFF-FFFF-FFFF-"
+#define L2CAP_LE_REQUEST_TIMEOUT 15 /* 15 sec */
 
 typedef struct {
        int sock_fd;
+       guint req_timer;
        int chan;
        char uuid[BT_UUID_STRING_SIZE];
        char address[BT_ADDRESS_STRING_SIZE];
@@ -48,6 +50,26 @@ typedef struct {
 
 static bt_socket_info_t *pending_conn_info;
 
+static bool __bt_socket_l2cap_timeout_cb(void)
+{
+       BT_INFO("No response from bluez, so forcely clear timer");
+
+       if (pending_conn_info == NULL) {
+               BT_ERR("pending info does not exist!");
+               return FALSE;
+       }
+
+       BT_INFO("channel: %d", pending_conn_info->chan);
+
+       pending_conn_info->conn_cb(BLUETOOTH_ERROR_INTERNAL, pending_conn_info->sock_fd, pending_conn_info->address,
+                       pending_conn_info->uuid, pending_conn_info->chan);
+
+       g_free(pending_conn_info);
+       pending_conn_info = NULL;
+
+       return FALSE;
+}
+
 /* Function to handle socket disconnection */
 void __handle_socket_disconnected(event_socket_client_conn_t *client_info)
 {
@@ -78,6 +100,9 @@ void __handle_socket_disconnected(event_socket_client_conn_t *client_info)
                pending_conn_info->conn_cb(BLUETOOTH_ERROR_INTERNAL, client_info->fd, address,
                                pending_conn_info->uuid, pending_conn_info->chan);
 
+               if (pending_conn_info->req_timer)
+                       g_source_remove(pending_conn_info->req_timer);
+
                g_free(pending_conn_info);
                pending_conn_info = NULL;
        } else {
@@ -109,6 +134,9 @@ static void __handle_outgoing_client_socket_connected(event_socket_client_conn_t
                return;
        }
 
+       if (pending_conn_info->req_timer)
+               g_source_remove(pending_conn_info->req_timer);
+
        BT_INFO("socket_fd: %d, address: %s, uuid: %s, channel: %d",
                        client_info->fd, address,
                        pending_conn_info->uuid,
@@ -235,6 +263,9 @@ int _bt_socket_client_connect(int sock_type, char *address,
        else
                memset(pending_conn_info->uuid, 0x00, BT_UUID_STRING_SIZE);
 
+       pending_conn_info->req_timer = g_timeout_add_seconds(L2CAP_LE_REQUEST_TIMEOUT,
+                               (GSourceFunc)__bt_socket_l2cap_timeout_cb, NULL);
+
        BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }