Add l2cap channel EOF handling logic like rfcomm 92/308592/1
authorWootak Jung <wootak.jung@samsung.com>
Mon, 5 Dec 2022 03:46:53 +0000 (12:46 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Thu, 28 Mar 2024 02:33:32 +0000 (11:33 +0900)
Remove the unnecessary bluedroid specific logic

Change-Id: I9054e035d461bd6a8a5daa874e47747c920e1399
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
bt-api/bt-l2cap-le-client.c

index 8e61c74..82f8d4c 100644 (file)
@@ -123,15 +123,12 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
        bt_event_info_t *event_info;
        bluetooth_l2cap_le_received_data_t data_r;
        l2cap_le_client_conn_info_t *conn_info;
-
        int fd;
-#ifdef TIZEN_BLUEDROID_PORTING
-       char len_buf[2] = {0, 0};
-#endif
        gsize len = 0;
        char *buffer;
        GError *err = NULL;
        GIOStatus status = G_IO_STATUS_NORMAL;
+       static int resource_unavailable_cnt = 0;
 
        BT_DBG("+");
 
@@ -141,40 +138,10 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
                goto fail;
        }
 
-#ifdef TIZEN_BLUEDROID_PORTING
-       /* Read buffer length from socket */
-       status = g_io_channel_read_chars(chan, len_buf, sizeof(len_buf), &len, &err);
-       if (status != G_IO_STATUS_NORMAL) {
-               BT_ERR("IO Channel read is failed with %d", status);
-               if (err) {
-                       BT_ERR("IO Channel read error [%s]", err->message);
-                       if (status == G_IO_STATUS_ERROR &&
-                                       !g_strcmp0(err->message,
-                                               "Connection reset by peer"))
-                               BT_ERR("cond : %d", cond);
-
-                       g_error_free(err);
-               }
-               goto fail;
-       }
-
-       if (len == 0) {
-               BT_ERR("Length is zero, remote end hang up");
-               goto fail;
-       }
-
-       len = (unsigned char)len_buf[0] + ((unsigned char)len_buf[1] << 8);
-       BT_INFO("lecap_le Recieved buffer len: %d", len);
-
-       /* Read len bytes in buffer from socket */
-       buffer = g_malloc0(len + 1);
-       status = g_io_channel_read_chars(chan, buffer, len, &len, &err);
-#else
        buffer = g_malloc0(BT_L2CAP_LE_BUFFER_LEN + 1);
        g_io_channel_set_buffer_size(chan, BT_L2CAP_LE_BUFFER_LEN);
        status = g_io_channel_read_chars(chan, buffer, BT_L2CAP_LE_BUFFER_LEN,
                        &len, &err);
-#endif
        if (status != G_IO_STATUS_NORMAL) {
                BT_ERR("IO Channel read is failed with %d", status);
                g_free(buffer);
@@ -189,8 +156,18 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
                        g_error_free(err);
                }
 
+               if (status == G_IO_STATUS_ERROR ||
+                       status == G_IO_STATUS_EOF) {
+                       goto fail;
+               } else if (status == G_IO_STATUS_AGAIN) {
+                       resource_unavailable_cnt++;
+                       if (resource_unavailable_cnt > 10)
+                               goto fail;
+               }
+
                return TRUE;
        }
+       resource_unavailable_cnt = 0;
 
        if (len == 0) {
                BT_ERR("Length is zero, remote end hang up");