From 334f3bf0f8a33aa630678b3ab67357b010deca4f Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Wed, 18 Nov 2020 09:51:47 -0600 Subject: fix problems???? --- P3/.vscode/launch.json | 2 +- P3/server.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'P3') diff --git a/P3/.vscode/launch.json b/P3/.vscode/launch.json index 9890b76..d241d6a 100644 --- a/P3/.vscode/launch.json +++ b/P3/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/web_server", - "args": ["9000", "testing", "10", "1", "0", "99", "0"], + "args": ["9000", "testing", "10", "10", "0", "99", "0"], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/P3/server.c b/P3/server.c index b13d7fc..1e7a6c3 100644 --- a/P3/server.c +++ b/P3/server.c @@ -83,8 +83,8 @@ void deleteCache(){ request_t *tempReq = NULL; while (Q != NULL) { tempReq = Q; - free(tempReq->request); Q = Q->next; + free(tempReq->request); free(tempReq); } // De-allocate/free the cache memory @@ -170,14 +170,15 @@ void * dispatch(void *arg) { // Accept client connection and get the fd int newReq = accept_connection(); if (newReq > INVALID) { + pthread_mutex_lock(&Qlock); request_t* traverse = Q; // Get request from the client // Add the request into the queue for(int i = 0; i < qLen; i++) { - if (traverse == NULL) { + if (traverse == NULL || traverse->next == NULL) { //Add things to queue. Lock & unlock to prevent a deadlock - pthread_mutex_lock(&Qlock); + request_t *tempNode = (request_t *)calloc(1, sizeof(request_t)); char* dispatchBuf = (char *) malloc(BUFF_SIZE); // Buffer to store the requested filename if (get_request(newReq, dispatchBuf) != 0) { @@ -189,7 +190,12 @@ void * dispatch(void *arg) { tempNode->fd = newReq; tempNode->request = dispatchBuf; tempNode->next = NULL; - Q = tempNode; + if (traverse == NULL) { + Q = tempNode; + } else { + traverse->next = tempNode; + } + pthread_mutex_unlock(&Qlock); break; } else { -- cgit v1.2.3