From 890d327b5b35474f7cbb55fe1efcc72f64a5e609 Mon Sep 17 00:00:00 2001 From: Pysicopadingo Date: Thu, 27 Oct 2022 02:03:28 +0200 Subject: [PATCH] Add Dispatcher --- src/server.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/server.c b/src/server.c index 716316c..dfa8b3a 100644 --- a/src/server.c +++ b/src/server.c @@ -220,7 +220,31 @@ int disconnect_client(int client_id) { } /* Thread, parses and handles messages */ +/* Thread, Dispatcher : pop message from the stack, parse it and send it to the good ClientSender */ void *Dispatcher(void *arg) { + char buf = 0; + char *message[]; + int n = 0 ; + int k = 0 ; + + while (1) { + /* Read 1 bytes at a time, because we don't know how long the message will be */ + while ((n = read(stack_fd, buf, 1)) > 0) { + message[k++] = buf; + if (buf == '\n'){ + k = 0; + printf("Message received : %c", &message); + + /* TODO : parse(*message); Do we do that into a separate thread ? */ + + /* TODO :Writing Message into pipe */ + } + if (n < 0) { + fprintf(stderr, "ERROR: Dispatcher failed to read from stack\n"); + break; + } + } + } pthread_exit(0); }