diff --git a/src/server.c b/src/server.c index 9ada393..02041cf 100644 --- a/src/server.c +++ b/src/server.c @@ -22,7 +22,7 @@ int main(void) { int message_pipe[2]; struct sockaddr_in server_socket; struct sockaddr_in client_socket; - pthread_t clientlistener, clientsender; + pthread_t dispatcher, clientlistener, clientsender; void *retval; pid_t pid; long addr_len; @@ -80,6 +80,11 @@ int main(void) { return EXIT_FAILURE; } + if (pthread_create(&dispatcher, NULL, Dispatcher, NULL) != 0) { + fprintf(stderr, "pthread_create: error for Dispatcher\n"); + exit(EXIT_FAILURE); + } + /* Loop to accept incoming connections */ while (1) { if ((client_sockid = accept(serv_sockid, (struct sockaddr *) &client_socket, (socklen_t *) &addr_len)) < 0) { @@ -116,12 +121,14 @@ int main(void) { exit(EXIT_FAILURE); } + // TODO: joining here prevents creating other clients, need to move the joins to some client_disconnect function (void) pthread_join(clientsender, &retval); (void) pthread_join(clientlistener, &retval); } } printf("Server end, closing connection\n"); + (void) pthread_join(dispatcher, &retval); close(serv_sockid); return EXIT_SUCCESS; }