aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-12-06 18:28:50 -0600
committerMatt Strapp <strap012@umn.edu>2020-12-06 18:28:50 -0600
commitc4808fdda05c4b0a2609eb93da56de09738d5363 (patch)
treec70e84dd2e2ef053ee0fd911c53a8bbc9204e59f
parentoops (diff)
downloadcsci4061-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
-rw-r--r--P4/util.c6
1 files 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);
}