aboutsummaryrefslogtreecommitdiffstats
path: root/P3/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'P3/server.c')
-rw-r--r--P3/server.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/P3/server.c b/P3/server.c
index 80c4448..a1d0527 100644
--- a/P3/server.c
+++ b/P3/server.c
@@ -52,6 +52,7 @@ void * dynamic_pool_size_update(void *arg) {
// Function to check whether the given request is present in cache
int getCacheIndex(char *request){
/// return the index if the request is present in the cache
+ return 0;
}
// Function to add the request and its file content into the cache
@@ -141,7 +142,13 @@ void * worker(void *arg) {
/**********************************************************************************/
+//Flag for when server needs to die nicely
static volatile sig_atomic_t exitFlag = 0;
+
+//Sets exit flag so process can die happily and not sad.
+static void eggs(int signo) {
+ exitFlag |= 1;
+}
int main(int argc, char **argv) {
// Error check on number of arguments
@@ -151,28 +158,43 @@ int main(int argc, char **argv) {
}
// Get the input args
- int port = argv[3];
+
+ //Port
+ int port = (int) *argv[3];
+
+ //Webroot path
char* path = argv[4];
- int dispatchers = argv[5];
- int workers = argv[6];
- int dynFlag = argv[7];
- int qLen = argv[8];
- int cSiz = argv[9];
+
+ //(static) number of dispatchers
+ int dispatchers = (int) *argv[5];
+
+ //(static) number of workers
+ int workers = (int) *argv[6];
+
+ //Dynamic worker flag
+ int dynFlag = (int) *argv[7];
+
+ //Queue Length
+ int qLen = (int) *argv[8];
+
+ //Max cache size
+ int cSiz = (int) *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");
+ printf("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");
+ printf("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");
+ printf("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");
+ printf("Queue length is invalid.\n");
return -1;
}
// Change SIGINT action for grace termination
@@ -182,17 +204,21 @@ int main(int argc, char **argv) {
act.sa_flags = 0;
if (sigemptyset(&act.sa_mask) == -1 ||
sigaction(SIGINT, &act, NULL) == -1) {
- perror("SIGINT handler failed.\n");
+ printf("SIGINT handler failed.\n");
return -1;
}
// Open log file
- FILE* logfile = fopen("serverlog.txt", "a+");
+ FILE* logfile = fopen("webserver_log", "a+");
// Change the current working directory to server root directory
if (chdir("testing") == -1) {
- perror("Could not find root webserver directory testing. Exiting\n");
+ printf("Could not find root webserver directory \"testing\". Exiting\n");
return -1;
}
// Initialize cache (extra credit B)
+<<<<<<< HEAD
+
+=======
+>>>>>>> startmain
// Start the server
init(port);
// Create dispatcher threads (make detachable????)
@@ -217,8 +243,14 @@ 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. (please wait for the threads to die)\n");
// Print the number of pending requests in the request queue
+ /*TODO*/
+ //Kill all dispatch and worker threads
+ for (int j=0; j<dispatchers; j++)
+ pthread_cancel(dThreads[j]);
+ for (int j=0; j<workers;j++)
+ pthread_cancel(wThreads[j]);
// close log file
fclose(logfile);
// Remove cache (extra credit B)
@@ -230,7 +262,3 @@ int main(int argc, char **argv) {
printf("This should never be printed.");
return 42;
}
-static void eggs(int signo) {
- exitFlag |= 1;
-}
-