Make stack gloabl, fix Dispatcher message processing

This commit is contained in:
flyingscorpio@clevo 2022-10-27 09:55:58 +02:00
parent a8c71c6abd
commit d447076265

View file

@ -17,10 +17,10 @@
* sender_thread
* */
struct client_details clients[MAX_CLIENTS];
int stack[2];
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;
@ -219,28 +219,27 @@ 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[];
char buf[BUF_LEN];
char message[1024];
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'){
while ((n = read(stack[0], buf, 1)) > 0) {
message[k++] = buf[n - 1];
if (buf[n - 1] == '\n'){
message[k++] = '\0';
k = 0;
printf("Message received : %c", &message);
/* TODO : parse(*message); Do we do that into a separate thread ? */
/* TODO :Writing Message into pipe */
printf("Message received : %s", message);
/* TODO: parse(*message); Do we do that in a separate thread ? */
/* TODO: Writing Message into pipe */
}
if (n < 0) {
fprintf(stderr, "ERROR: Dispatcher failed to read from stack\n");
break;
}
}
if (n < 0) {
fprintf(stderr, "ERROR: Dispatcher failed to read from stack\n");
break;
}
}
}
pthread_exit(0);
}