From 98563094d78f86ddad16a24fe37c4bd0264d4711 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Fri, 13 Nov 2020 19:16:12 -0600 Subject: Add error checking --- P3/server.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/P3/server.c b/P3/server.c index 868e0fe..0226e41 100644 --- a/P3/server.c +++ b/P3/server.c @@ -131,9 +131,30 @@ int main(int argc, char **argv) { } // Get the input args - + int port = argv[3]; + char* path = argv[4]; + int dispatchers = argv[5]; + int workers = argv[6]; + int dynFlag = argv[7]; + int qLen = argv[8]; + int cSiz = argv[9]; // Perform error checks on the input arguments - + if (port < 1025 || port > 65535) { + perror("Invalid port. Port must be greater than 1024 or less than 65536.\n"); + return -1; + } + if (dispatchers > MAX_THREADS || dispatchers < 1) { + perror("Number of dispatchers is invalid. It must be greater than 0 or less than 101.\n"); + return -1; + } + if (workers > MAX_THREADS || workers < 1) { + perror("Number of dispatchers is invalid. It must be greater than 0 or less than 101.\n"); + return -1; + } + if (qLen > MAX_queue_len || qLen <= 0) { + perror("Queue length is invalid.\n"); + return -1; + } // Change SIGINT action for grace termination // Open log file -- cgit v1.2.3