aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-12-08 08:54:40 -0600
committerMatt Strapp <strap012@umn.edu>2020-12-08 08:54:40 -0600
commit1c2779e93cbb7e3e27ec0c822f1035e5744a0575 (patch)
treeadf7447c5f09bbbc74100433b1678e171d333371
parentadd error checking (diff)
downloadcsci4061-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.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/P4/util.c b/P4/util.c
index 5c5bdb2..3967767 100644
--- a/P4/util.c
+++ b/P4/util.c
@@ -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);
}