From 8907bd0ac909e05880b18ada86123c8b7517ce37 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 27 May 2015 00:20:38 +0100 Subject: [PATCH] Added kill_recv --- src/server/server.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/server/server.c b/src/server/server.c index 1b8d922..1680703 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -32,6 +32,7 @@ static void _shutdown(void); static int listen_socket; static pthread_t server_thread; +static gboolean kill_recv = FALSE; void write_stream(const char * const stream) @@ -72,6 +73,11 @@ read_stream(void) errno = 0; while (TRUE) { + if (kill_recv) { + _shutdown(); + return 0; + } + // send anything from queue pthread_mutex_lock(&send_queue_lock); GList *curr_send = send_queue; @@ -235,6 +241,8 @@ server_run(int port) send_queue = NULL; pthread_mutex_unlock(&send_queue_lock); + kill_recv = FALSE; + client = NULL; log_init(); log_println("Starting on port: %d...", port); @@ -304,6 +312,7 @@ server_send(char *stream) void server_stop(void) { + kill_recv = TRUE; pthread_join(server_thread, NULL); } @@ -327,5 +336,6 @@ _shutdown(void) g_list_free_full(send_queue, free); send_queue = NULL; pthread_mutex_unlock(&send_queue_lock); + log_close(); }