From 6c181cdbc43c20a4e8474f46bb9508dd28d8ebac Mon Sep 17 00:00:00 2001 From: Pysicopadingo Date: Thu, 27 Oct 2022 02:01:33 +0200 Subject: [PATCH] Add Stack --- src/server.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 039ec20..716316c 100644 --- a/src/server.c +++ b/src/server.c @@ -3,7 +3,10 @@ #include #include #include +#include #include +#include +#include #include "server.h" #include "common.h" @@ -20,6 +23,7 @@ struct client_details clients[MAX_CLIENTS]; int main(int argc, char *argv[]) { int server_port, serv_sockid, client_sockid, client_id; + int stack[2]; int message_pipe[2]; struct sockaddr_in server_socket; struct sockaddr_in client_socket; @@ -81,6 +85,11 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } + if (pipe(stack) != 0){ + fprintf(stderr, "ERROR : failed to create stack pipe\n"); + return EXIT_FAILURE; + } + if (pthread_create(&dispatcher, NULL, Dispatcher, NULL) != 0) { fprintf(stderr, "pthread_create: error for Dispatcher\n"); exit(EXIT_FAILURE); @@ -135,6 +144,9 @@ int main(int argc, char *argv[]) { disconnect_client(i); } + close(stack[0]); + close(stack[1]); + printf("Server end, closing connection\n"); (void) pthread_join(dispatcher, &retval); close(serv_sockid); @@ -221,7 +233,9 @@ void *ClientListener(void *arg) { while (1) { /* Read n bytes at a time, because we don't know how long the message will be */ while ((n = read(details.sockid, buf, BUF_LEN)) > 0) { - // TODO: do somethig with the stream (push to global stack?) + /* TODO: Get mutex */ + write(stack[1], buf, n); + /* TODO: Free mutex */ } if (n < 0) { fprintf(stderr, "ERROR: read\n");