aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2020-11-16 20:15:02 -0600
committerMatt Strapp <strap012@umn.edu>2020-11-16 20:15:02 -0600
commitcfeab2b8c0711f73f9db533d5dd7bdaafa30fc74 (patch)
tree2fb88ebdf535b9f1d426f7bd0e736c372cf15859
parentadd stuffs (diff)
downloadcsci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar.gz
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar.bz2
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar.lz
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar.xz
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.tar.zst
csci4061-cfeab2b8c0711f73f9db533d5dd7bdaafa30fc74.zip
Add things
-rw-r--r--P3/server.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/P3/server.c b/P3/server.c
index ea9eb3d..7c352fc 100644
--- a/P3/server.c
+++ b/P3/server.c
@@ -22,6 +22,7 @@
int port, workers, dispatchers, dynFlag, qLen, cSiz = 0;
char* path;
+pthread_mutex_t Qlock;
/*
THE CODE STRUCTURE GIVEN BELOW IS JUST A SUGGESTION. FEEL FREE TO MODIFY AS NEEDED
@@ -82,7 +83,7 @@ void initCache(){
/* ************************************ Utilities ********************************/
// Function to get the content type from the request
-char* getContentType(char * mybuf) {
+char* Type(char * mybuf) {
// Should return the content type based on the file type in the request
// (See Section 5 in Project description for more details)
char* ext = strrchr(mybuf, '.');
@@ -127,9 +128,12 @@ void * dispatch(void *arg) {
// Add the request into the queue
for(int i = 0; i < qLen; i++) {
if (traverse == NULL) {
- //Add sh!t to queue
+ //Add things to queue. Lock & unlock to prevent a race condition
+ pthread_mutex_lock(&Qlock);
request_t * tempNode = (request_t*) calloc(1, sizeof(request_t *)); // Yes, he spelled it like that on purpose
char* tempBuf = malloc(BUFF_SIZE); // Buffer to store the requested filename
+ pthread_mutex_unlock(&Qlock);
+
if (get_request(newReq, tempBuf) != 0) {
continue; // If get_request fails, try again
}
@@ -152,12 +156,13 @@ void * dispatch(void *arg) {
void * worker(void *arg) {
while (1) {
- request_t *traverse = Q;
- if (traverse == NULL)
+ request_t *head = Q;
+ if (head == NULL)
continue;
-
// Get the request from the queue
-
+ pthread_mutex_lock(&Qlock);
+ return_result(head->fd, getContentType(head->request), );
+ pthread_mutex_unlock(&Qlock);
// Get the data from the disk or the cache (extra credit B)
// Log the request into the file and terminal