From 8411f404cfd6d3dd0a8493d1b29764ae6d3dea3b Mon Sep 17 00:00:00 2001 From: Jaeyun Date: Wed, 13 Jul 2022 11:43:29 +0900 Subject: [PATCH] [Socket] condition to release thread Update src to close socket and release msg thread. GSocket will close socket automatically if its ref count is 0. Signed-off-by: Jaeyun --- .../nnstreamer-edge-internal.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index e1b44ab..8cdb003 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -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); -- 2.34.1