From 7efdc39f96c317f436be328722ab1009780db8f5 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Sun, 15 Nov 2020 19:19:25 -0600 Subject: work on many things --- P3/server.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/P3/server.c b/P3/server.c index 323015a..21b47c3 100644 --- a/P3/server.c +++ b/P3/server.c @@ -160,25 +160,25 @@ int main(int argc, char **argv) { // Get the input args //Port - int port = (int) *argv[3]; + int port = atoi(argv[3]); //Webroot path char* path = argv[4]; //(static) number of dispatchers - int dispatchers = (int) *argv[5]; + int dispatchers = atoi(argv[5]); //(static) number of workers - int workers = (int) *argv[6]; + int workers = atoi(argv[6]); //Dynamic worker flag - int dynFlag = (int) *argv[7]; + int dynFlag = atoi(argv[7]); //Queue Length - int qLen = (int) *argv[8]; + int qLen = atoi(argv[8]); //Max cache size - int cSiz = (int) *argv[9]; + int cSiz = atoi(argv[9]); // Perform error checks on the input arguments if (port < 1025 || port > 65535) { @@ -204,14 +204,14 @@ int main(int argc, char **argv) { act.sa_flags = 0; if (sigemptyset(&act.sa_mask) == -1 || sigaction(SIGINT, &act, NULL) == -1) { - printf("SIGINT handler failed.\n"); + perror("SIGINT Handler Error"); return -1; } // Open log file FILE* logfile = fopen("webserver_log", "a+"); // Change the current working directory to server root directory - if (chdir("testing") == -1) { - printf("Could not find root webserver directory \"testing\". Exiting\n"); + if (chdir(path) == -1) { + perror("Directory Change error"); return -1; } // Initialize cache (extra credit B) @@ -228,10 +228,11 @@ int main(int argc, char **argv) { pthread_create(&wThreads[i], NULL, worker, NULL); //TODO: Worker arguments } // Create dynamic pool manager thread (extra credit A) - /*Commented out for now as it is not needed + if (dynFlag) { pthread_t pThread; - pthread_create(pThread, NULL, dynamic_pool_size_update, NULL); //TODO: possible arguments - */ + pthread_create(&pThread, NULL, dynamic_pool_size_update, NULL); //TODO: possible arguments + } + //Server loop (RUNS FOREVER) while (1) { @@ -239,16 +240,28 @@ int main(int argc, char **argv) { // Terminate server gracefully if (exitFlag){ - printf("SIGINT caught, exiting now. (please wait for the threads to die)\n"); + printf("SIGINT caught, exiting now.\nWorker threads now being killed.\n"); // Print the number of pending requests in the request queue /*TODO*/ //Kill all dispatch and worker threads - for (int j=0; j