diff --git a/src/client.c b/src/client.c index 7870851fc..3578d2aed 100644 --- a/src/client.c +++ b/src/client.c @@ -17,6 +17,7 @@ #define BUFFER_SIZE 4096 static int client_enabled = 0; +static int running = 0; static int sd = 0; static char recv_buffer[QUEUE_SIZE] = {0}; static thrd_t recv_thread; @@ -150,8 +151,13 @@ int recv_worker(void *arg) { while (1) { char data[BUFFER_SIZE] = {0}; if (recv(sd, data, BUFFER_SIZE - 1, 0) <= 0) { - perror("recv"); - exit(1); + if (running) { + perror("recv"); + exit(1); + } + else { + break; + } } while (1) { int done = 0; @@ -198,6 +204,7 @@ void client_start() { if (!client_enabled) { return; } + running = 1; mtx_init(&mutex, mtx_plain); if (thrd_create(&recv_thread, recv_worker, NULL) != thrd_success) { perror("thrd_create"); @@ -209,6 +216,7 @@ void client_stop() { if (!client_enabled) { return; } + running = 0; close(sd); // if (thrd_join(recv_thread, NULL) != thrd_success) { // perror("thrd_join");