Add Dispatcher

This commit is contained in:
Pysicopadingo 2022-10-27 02:03:28 +02:00
parent 6c181cdbc4
commit 890d327b5b

View file

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