From 1e7fbc03a896cd670ff20f879bcec8e0069a5399 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 22 Feb 2023 09:56:23 +0100 Subject: [PATCH] added way to stop server --- src/chat/main/server.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/chat/main/server.c b/src/chat/main/server.c index cec3291..b4ca7b5 100644 --- a/src/chat/main/server.c +++ b/src/chat/main/server.c @@ -18,12 +18,16 @@ along with this program. If not, see . #include +#include + #include int main(void) { int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET pthread_t thread; + size_t line_length_buffer; + char *line_buffer; if (listen_socket < 0) why2_die("Failed creating socket."); @@ -43,9 +47,21 @@ int main(void) pthread_create(&thread, NULL, why2_accept_thread, &listen_socket); - //TODO: Add getline() + for (;;) + { + getline(&line_buffer, &line_length_buffer, stdin); - pthread_join(thread, NULL); + if (strcmp(line_buffer, "!exit\n") == 0) //USER REQUESTED PROGRAM EXIT + { + printf("Exiting...\n"); + break; + } + } + + //TODO: Exit threads + + free(line_buffer); + close(listen_socket); return 0; } \ No newline at end of file