From c4808fdda05c4b0a2609eb93da56de09738d5363 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Sun, 6 Dec 2020 18:28:50 -0600 Subject: Do everything sans Extra Credit --- P4/util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/P4/util.c b/P4/util.c index 02ce666..e924575 100644 --- a/P4/util.c +++ b/P4/util.c @@ -17,6 +17,7 @@ //Global socket int sockfd; +pthread_mutex_t connection = PTHREAD_MUTEX_INITIALIZER; /********************************************** * init @@ -65,14 +66,15 @@ void init(int port) { - if the return value is negative, the request should be ignored. ***********************************************/ int accept_connection(void) { - + pthread_mutex_lock(&connection); struct sockaddr_in address; int addrlen = sizeof(address), new_socket = 0; if ((new_socket = accept(sockfd, (struct sockaddr *)&address, (socklen_t*)&addrlen))<0) { perror("Accept"); + pthread_mutex_unlock(&connection); return -1; } - printf("%d\n", new_socket); + pthread_mutex_unlock(&connection); return(new_socket); } -- cgit v1.2.3