[Socket] condition to release thread
authorJaeyun <jy1210.jung@samsung.com>
Wed, 13 Jul 2022 02:43:29 +0000 (11:43 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Mon, 18 Jul 2022 02:35:28 +0000 (11:35 +0900)
Update src to close socket and release msg thread.
GSocket will close socket automatically if its ref count is 0.

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

index e1b44ab52764583e2da47a22c9ec0fd2ea59febe..8cdb003302d90f041cadbd59ff6b96e8ba9485a5 100644 (file)
@@ -397,12 +397,11 @@ error:
 static bool
 _nns_edge_close_connection (nns_edge_conn_s * conn)
 {
-  GError *err = NULL;
-
   if (!conn)
     return false;
 
-  if (conn->running && conn->msg_thread) {
+  /* Stop and clear the message thread. */
+  if (conn->msg_thread) {
     conn->running = 0;
     pthread_cancel (conn->msg_thread);
     pthread_join (conn->msg_thread, NULL);
@@ -413,16 +412,15 @@ _nns_edge_close_connection (nns_edge_conn_s * conn)
     nns_edge_cmd_s cmd;
 
     /* Send error before closing the socket. */
+    nns_edge_logd ("Send error cmd to close connection.");
     _nns_edge_cmd_init (&cmd, _NNS_EDGE_CMD_ERROR, 0);
     _nns_edge_cmd_send (conn, &cmd);
 
-    if (!g_socket_close (conn->socket, &err)) {
-      nns_edge_loge ("Failed to close socket: %s", err->message);
-      g_clear_error (&err);
-      return false;
-    }
-    g_object_unref (conn->socket);
-    conn->socket = NULL;
+    /**
+     * Close and release the socket.
+     * Using GSocket, if its last reference is dropped, it will close socket automatically.
+     */
+    g_clear_object (&conn->socket);
   }
 
   g_free (conn->ip);