diff options
author | Matt Strapp <strap012@umn.edu> | 2020-11-18 06:47:32 -0600 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2020-11-18 06:47:32 -0600 |
commit | 950546b6671ae1a80e5facb4828c15d779bb970f (patch) | |
tree | 72bee1f716809d113b65cb50a2ae2d5c5cb502ba /P3 | |
parent | add to cache (diff) | |
download | csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar.gz csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar.bz2 csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar.lz csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar.xz csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.tar.zst csci4061-950546b6671ae1a80e5facb4828c15d779bb970f.zip |
do some things
Diffstat (limited to '')
-rw-r--r-- | P3/server.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/P3/server.c b/P3/server.c index 027fc62..65da241 100644 --- a/P3/server.c +++ b/P3/server.c @@ -60,7 +60,15 @@ 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; + cache_entry_t *traverse = dynQ; + int index = 0; + while (traverse != NULL) { + if (!strcmp(request, traverse->request)) { + return index; + } + index++; + } + return -1; } // Function to add the request and its file content into the cache @@ -71,19 +79,27 @@ void addIntoCache(char *mybuf, char *memory , int memory_size){ // clear the memory allocated to the cache void deleteCache(){ + + request_t *tempReq = NULL; + while (Q != NULL) { + tempReq = Q; + Q = Q->next; + free(tempReq); + } // De-allocate/free the cache memory - free(Q); - free(dynQ); + cache_entry_t *tempCache = NULL; + while (dynQ != NULL) + { + tempCache = dynQ; + dynQ = dynQ->next; + free(tempCache); + } } // Function to initialize the cache void initCache(){ // Allocating memory and initializing the cache array - dynQ = (cache_entry_t *) calloc(sizeof(cache_entry_t), cSiz); - if (dynQ == NULL) { - printf("malloc cannot allocate the initial requested memory.\n"); - exit(-2); - } + } /**********************************************************************************/ @@ -163,7 +179,7 @@ void * dispatch(void *arg) { //Add things to queue. Lock & unlock to prevent a deadlock pthread_mutex_lock(&Qlock); - request_t * tempNode = (request_t*) calloc(1, sizeof(request_t *)); + request_t * tempNode = (request_t*) calloc(1, sizeof(request_t)); char* dispatchBuf = (char *) malloc(BUFF_SIZE); // Buffer to store the requested filename pthread_mutex_unlock(&Qlock); @@ -336,7 +352,6 @@ int main(int argc, char **argv) { pthread_t pThread; pthread_create(&pThread, &attr, dynamic_pool_size_update, NULL); //TODO: possible arguments } - //Server loop (RUNS FOREVER) while (1) { @@ -353,6 +368,7 @@ int main(int argc, char **argv) { printf("There are %d pending requests left in the queue.\n", pendReqs); // Remove cache (extra credit B) deleteCache(); + printf("Cache has been deleted.\n"); return 0; } } |