[Edge] remove client when received error
authorJaeyun <jy1210.jung@samsung.com>
Mon, 11 Jul 2022 10:40:05 +0000 (19:40 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Wed, 27 Jul 2022 03:33:33 +0000 (12:33 +0900)
In message thread, remove connection data when received error from client.
Internally error command means closing socket.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index a34d3b04d69152e81ac9321408a7350f3af0fd7c..4d6e85cc791dfb3e05ace7fafa35c2ddf49d9ae4 100644 (file)
@@ -675,6 +675,7 @@ _nns_edge_message_handler (void *thread_data)
   nns_edge_handle_s *eh;
   nns_edge_conn_s *conn;
   nns_edge_cmd_s cmd;
+  bool remove_connection = false;
   int64_t client_id;
   char *val;
   int ret;
@@ -705,14 +706,18 @@ _nns_edge_message_handler (void *thread_data)
     ret = _nns_edge_cmd_receive (conn, &cmd);
     if (ret != NNS_EDGE_ERROR_NONE) {
       nns_edge_loge ("Failed to receive data from the connected node.");
+      remove_connection = true;
       break;
     }
 
     if (cmd.info.cmd == _NNS_EDGE_CMD_ERROR) {
       nns_edge_loge ("Received error, stop msg thread.");
       _nns_edge_cmd_clear (&cmd);
+      remove_connection = true;
       break;
-    } else if (cmd.info.cmd != _NNS_EDGE_CMD_TRANSFER_DATA) {
+    }
+
+    if (cmd.info.cmd != _NNS_EDGE_CMD_TRANSFER_DATA) {
       /** @todo handle other cmd later */
       _nns_edge_cmd_clear (&cmd);
       continue;
@@ -745,6 +750,14 @@ _nns_edge_message_handler (void *thread_data)
     _nns_edge_cmd_clear (&cmd);
   }
 
+  /* Received error message from client, remove connection from table. */
+  if (remove_connection) {
+    nns_edge_logd
+        ("Received error from client, remove connection of client (ID: %ld).",
+        (long int) client_id);
+    g_hash_table_remove (eh->conn_table, GUINT_TO_POINTER (client_id));
+  }
+
   conn->running = 0;
   return NULL;
 }