From 05e855cec496da14e46bfcffeb30fb11a2254ed7 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Tue, 8 Dec 2020 08:49:27 -0600 Subject: add error checking --- P4/util.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/P4/util.c b/P4/util.c index ded2dfa..5c5bdb2 100644 --- a/P4/util.c +++ b/P4/util.c @@ -102,22 +102,34 @@ int get_request(int fd, char *filename) { recv(fd, buffer, 2048, 0); if(sscanf(buffer, "%s %s %s", get, filename, http) < 2) { // Read HTTP Get request and parse - close(fd); + if (close(fd) == -1) { + perror("Socket close error"); + return -15; + } return -1; } else if (strcmp(get, "GET")) { - close(fd); + if (close(fd) == -1) { + perror("Socket close error"); + return -15; + } printf("Not a GET\n"); return -2; } else if (strlen(filename) > 1023) { - close(fd); + if (close(fd) == -1) { + perror("Socket close error"); + return -15; + } printf("Not sure but bad\n"); return -3; } for (int i=0; i