Fix infinite callback issue in EOF status
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-rfcomm-server.c
index 4288819..7a4e32a 100644 (file)
@@ -264,13 +264,6 @@ static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
        return FALSE;
 }
 
-static gboolean __is_error_by_disconnect(GError *err)
-{
-       return !g_strcmp0(err->message, "Connection reset by peer") ||
-                       !g_strcmp0(err->message, "Connection timed out") ||
-                       !g_strcmp0(err->message, "Software caused connection abort");
-}
-
 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
                                                                gpointer data)
 {
@@ -312,43 +305,38 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
        }
 
        buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
-
        status =  g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
                                                &len, &err);
        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 (!err)
+
+               if (status == G_IO_STATUS_AGAIN)
                        return TRUE;
 
-               BT_ERR("IO Channel read error [%s]", err->message);
-               if (status == G_IO_STATUS_ERROR &&
-                   __is_error_by_disconnect(err)) {
-                       BT_ERR("cond : %d", cond);
+               if (err) {
+                       BT_ERR("IO Channel read error [%s]", err->message);
                        g_error_free(err);
+               }
 
-                       if (info->disconnect_idle_id > 0) {
-                               BT_INFO("Disconnect idle still not process remove source");
-                               g_source_remove(info->disconnect_idle_id);
-                               info->disconnect_idle_id = 0;
-                       }
-
-                       conn = __find_rfcomm_conn_with_fd(info, fd);
-                       if (conn == NULL) {
-                               BT_ERR("No Connection info found with FD [%d]", fd);
-                               return FALSE;
-                       }
+               if (info->disconnect_idle_id > 0) {
+                       BT_INFO("Disconnect idle still not process remove source");
+                       g_source_remove(info->disconnect_idle_id);
+                       info->disconnect_idle_id = 0;
+               }
 
-                       if (conn->disconnected == FALSE) {
-                               close(conn->fd);
-                               conn->disconnected = TRUE;
-                       }
-                       __rfcomm_server_disconnect(info);
+               conn = __find_rfcomm_conn_with_fd(info, fd);
+               if (conn == NULL) {
+                       BT_ERR("No Connection info found with FD [%d]", fd);
                        return FALSE;
                }
-               g_error_free(err);
-               return TRUE;
+
+               if (conn->disconnected == FALSE) {
+                       close(conn->fd);
+                       conn->disconnected = TRUE;
+               }
+               __rfcomm_server_disconnect(info);
+               return FALSE;
        }
 
        if (len == 0)
@@ -960,19 +948,17 @@ static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
        status =  g_io_channel_read_chars(chan, buffer,
                        BT_RFCOMM_BUFFER_LEN, &len, &err);
        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) {