From bca4804feaed8e5a5363972a6ac05e0f9586cee9 Mon Sep 17 00:00:00 2001 From: Bui Nguyen Quoc Thanh Date: Thu, 12 Aug 2021 14:05:38 +0700 Subject: dlt-control-common: shutdown and close socket Before cancelling the listening thread, try to shutdown and close the socket so that the listening thread is terminated intentionally Signed-off-by: Bui Nguyen Quoc Thanh --- src/console/dlt-control-common.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/console/dlt-control-common.c b/src/console/dlt-control-common.c index 96a15a2..abcaf92 100644 --- a/src/console/dlt-control-common.c +++ b/src/console/dlt-control-common.c @@ -630,6 +630,15 @@ int dlt_control_init(int (*response_analyzer)(char *, void *, int), */ int dlt_control_deinit(void) { + /* At this stage, we want to stop sending/receiving + * from dlt-daemon. So in order to avoid cancellation + * at recv(), shutdown and close the socket + */ + if (g_client.receiver.fd) { + shutdown(g_client.receiver.fd, SHUT_RDWR); + close(g_client.receiver.fd); + g_client.receiver.fd = -1; + } /* Stopping the listener thread */ pthread_cancel(daemon_connect_thread); pthread_join(daemon_connect_thread, NULL); -- cgit v1.2.1