diff options
author | Matt Strapp <strap012@umn.edu> | 2020-12-08 08:54:40 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-12-08 08:54:40 -0600 |
commit | 1c2779e93cbb7e3e27ec0c822f1035e5744a0575 (patch) | |
tree | adf7447c5f09bbbc74100433b1678e171d333371 | |
parent | add error checking (diff) | |
download | csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar.gz csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar.bz2 csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar.lz csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar.xz csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.tar.zst csci4061-1c2779e93cbb7e3e27ec0c822f1035e5744a0575.zip |
add error handling
-rw-r--r-- | P4/util.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -67,15 +67,24 @@ void init(int port) { - if the return value is negative, the request should be ignored. ***********************************************/ int accept_connection(void) { - pthread_mutex_lock(&connection); + if (pthread_mutex_lock(&connection) != 0) { + perror("Cannot aquire lock"); + return -3; + } 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); + perror("Accept error"); + if (pthread_mutex_unlock(&connection) != 0) { + perror("Cannot unlock"); + return -2; + } return -1; } - pthread_mutex_unlock(&connection); + if (pthread_mutex_unlock(&connection) != 0) { + perror("Cannot unlock"); + return -2; + } return(new_socket); } |