Fix infinite callback issue in EOF status
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-l2cap-le-server.c
index dcd25e1..1328c35 100644 (file)
@@ -408,9 +408,6 @@ static int __sock_read(int server_fd, char *buf, unsigned int len,
 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
                                                gpointer data)
 {
-#ifdef TIZEN_BLUEDROID_PORTING
-       char len_buf[2] = {0, 0};
-#endif
        char *buffer = NULL;
        gsize len = 0;
        int result = BLUETOOTH_ERROR_NONE;
@@ -430,55 +427,21 @@ static gboolean __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("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);
        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);
+               BT_ERR("IO Channel read is failed with %d(%s)", status, _bt_print_gio_status(status));
                g_free(buffer);
+
+               if (status == G_IO_STATUS_AGAIN)
+                       return TRUE;
+
                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;
-                       }
                        g_error_free(err);
                }
-
-               return TRUE;
+               goto fail;
        }
 
        if (len == 0) {
@@ -504,7 +467,8 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
        return TRUE;
 fail:
        BT_ERR("Failure occured, remove client connection");
-       server_info->conn_list = g_slist_remove(
+       if (server_info)
+               server_info->conn_list = g_slist_remove(
                        server_info->conn_list, client_info);
        __handle_l2cap_le_client_disconnected(server_info, client_info);
        client_info->watch_id = -1;
@@ -655,9 +619,6 @@ static int __l2cap_le_listen(l2cap_le_server_info_t *server_info, bool accept)
                int *fd_list_array;
                int len = 0;
 
-               if (!out_fd_list)
-                       return BLUETOOTH_ERROR_INTERNAL;
-
                fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
                BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
                server_info->server_fd = fd_list_array[0];
@@ -782,7 +743,8 @@ BT_EXPORT_API int bluetooth_l2cap_le_server_disconnect(int socket_fd)
                client_info->sock_fd = -1;
 
                /* Remove remote client info from l2cap_le server context */
-               server_info->conn_list = g_slist_remove(
+               if (server_info)
+                       server_info->conn_list = g_slist_remove(
                                server_info->conn_list, client_info);
 
                /* Release remote client info */