aboutsummaryrefslogtreecommitdiffstats
path: root/P4
diff options
context:
space:
mode:
Diffstat (limited to 'P4')
-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);
}