diff options
author | Matt Strapp <strap012@umn.edu> | 2020-12-06 18:28:50 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-12-06 18:28:50 -0600 |
commit | c4808fdda05c4b0a2609eb93da56de09738d5363 (patch) | |
tree | c70e84dd2e2ef053ee0fd911c53a8bbc9204e59f | |
parent | oops (diff) | |
download | csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar.gz csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar.bz2 csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar.lz csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar.xz csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.tar.zst csci4061-c4808fdda05c4b0a2609eb93da56de09738d5363.zip |
Do everything sans Extra Credit
Diffstat (limited to '')
-rw-r--r-- | P4/util.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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); } |