aboutsummaryrefslogtreecommitdiffstats
path: root/P3
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-11-18 09:51:47 -0600
committerMatt Strapp <strap012@umn.edu>2020-11-18 09:51:47 -0600
commit334f3bf0f8a33aa630678b3ab67357b010deca4f (patch)
tree339f52fc45abbe4ab4e94ffd55e97389bf471aac /P3
parentaaaaaaaaaaaaaaaaaaaa (diff)
downloadcsci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar.gz
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar.bz2
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar.lz
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar.xz
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.tar.zst
csci4061-334f3bf0f8a33aa630678b3ab67357b010deca4f.zip
fix problems????
Diffstat (limited to 'P3')
-rw-r--r--P3/.vscode/launch.json2
-rw-r--r--P3/server.c14
2 files changed, 11 insertions, 5 deletions
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 {