function 'request' for handling readN serverside
This commit is contained in:
@ -198,7 +198,6 @@ _end_dequeue:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* dequeue until we have s free space and expand the file by s */
|
||||
fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
|
||||
if(!q) {
|
||||
@ -211,6 +210,8 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
|
||||
|
||||
LOCK_RETURN(&q->m, NULL); /* begin me */
|
||||
|
||||
fileT **returnList = NULL; /* list of removed files */
|
||||
|
||||
if (q->head == NULL || q->len == 0) { /* empty queue */
|
||||
errno = ENOENT;
|
||||
goto _end_dequeueN;
|
||||
@ -235,10 +236,13 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
|
||||
goto _end_dequeueN;
|
||||
}
|
||||
|
||||
fileT **returnList = NULL; /* list of removed files */
|
||||
tmp = NULL;
|
||||
|
||||
returnList = calloc(1, sizeof(fileT*));
|
||||
returnList = calloc(1, sizeof(*returnList));
|
||||
if(!returnList) {
|
||||
perror("dequeueN: calloc");
|
||||
goto _end_dequeueN;
|
||||
}
|
||||
returnList[0] = NULL;
|
||||
|
||||
int purged = 0;
|
||||
@ -272,6 +276,8 @@ fileT ** dequeueN(queueT *q, char *filepath, size_t s) {
|
||||
|
||||
_end_dequeueN:
|
||||
UNLOCK_RETURN(&q->m, NULL);
|
||||
if(returnList)
|
||||
free(returnList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -765,6 +771,57 @@ _end_find_in_queue:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* return n files */
|
||||
fileT ** request(queueT *q, int n) {
|
||||
if(!q) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
if(n<=0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LOCK_RETURN(&q->m, NULL); /* begin me */
|
||||
|
||||
fileT **returnList = NULL; /* list of requested files */
|
||||
|
||||
if (q->head == NULL || q->len == 0) { /* empty queue */
|
||||
errno = ENOENT;
|
||||
goto _end_request;
|
||||
}
|
||||
|
||||
if(q->size < n) {
|
||||
errno = EINVAL;
|
||||
goto _end_request;
|
||||
}
|
||||
|
||||
returnList = calloc(n+1, sizeof(*returnList));
|
||||
if(!returnList) {
|
||||
perror("dequeueN: calloc");
|
||||
goto _end_request;
|
||||
}
|
||||
returnList[n] = NULL;
|
||||
|
||||
nodeT *tmp = q->head;
|
||||
for(int i=0; i<n; ++i) {
|
||||
if(tmp == NULL) {
|
||||
errno = ENOENT;
|
||||
goto _end_request;
|
||||
}
|
||||
returnList[i] = tmp->data;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
UNLOCK_RETURN(&q->m, NULL); /* end me */
|
||||
return returnList;
|
||||
|
||||
_end_request:
|
||||
UNLOCK_RETURN(&q->m, NULL);
|
||||
if(returnList)
|
||||
free(returnList);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* search for file and return result of search */
|
||||
int searchFile(queueT *q, char *filepath) {
|
||||
if(!q || !filepath) {
|
||||
|
||||
Reference in New Issue
Block a user