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); }