Api for managing files
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
#include <apiFile.h>
|
||||
|
||||
|
||||
void openFile(char *filepath, int flags, queueT *q, long fd_c, logT *logFileT);
|
||||
|
||||
|
||||
void readFile(char *filepath, queueT *q, long fd_c, logT *logFileT);
|
||||
|
||||
|
||||
void readNFiles(char *numStr, queueT *q, long fd_c, logT *logFileT);
|
||||
|
||||
|
||||
void writeFile(char *filepath, size_t size, queueT *q, long fd_c, logT *logFileT, int append);
|
||||
|
||||
|
||||
void lockFile(char *filepath, queueT *q, long fd_c, logT *logFileT, pthread_mutex_t *lock, waitingT **waiting);
|
||||
|
||||
|
||||
void unlockFile(char *filepath, queueT *q, long fd_c, logT *logFileT, pthread_mutex_t *lock, waitingT **waiting);
|
||||
|
||||
|
||||
void closeFile(char *filepath, queueT *q, long fd_c, logT *logFileT, pthread_mutex_t *lock, waitingT **waiting);
|
||||
|
||||
|
||||
void removeFile(char *filepath, queueT *q, long fd_c, logT *logFileT, pthread_mutex_t *lock, waitingT **waiting);
|
||||
|
||||
|
||||
|
||||
int sendFile(fileT *f, long fd_c, logT *logFileT);
|
||||
|
||||
|
||||
int addWaiting(waitingT **waiting, char *file, int fd);
|
||||
|
||||
|
||||
int removeFirstWaiting(waitingT **waiting, char *file);
|
||||
|
||||
|
||||
void clearWaiting(waitingT **waiting);
|
||||
|
||||
@ -6,6 +6,13 @@
|
||||
/* TODO: include lib di logging */
|
||||
/* TODO: finire tutte le descrizioni */
|
||||
|
||||
// Lista dei client in attesa su una lock
|
||||
typedef struct struct_waiting {
|
||||
long fd; // client in attesa
|
||||
char *file; // file su cui si vuole acquisire la lock
|
||||
struct struct_waiting *next; // puntatore al prossimo elemento della lista
|
||||
} waitingT;
|
||||
|
||||
/**
|
||||
* Apri o crea un nuovo file
|
||||
* \param filepath: nome del file
|
||||
|
||||
@ -34,7 +34,6 @@ static void *workerpool_thread(void *threadpool) {
|
||||
|
||||
LOCK_RETURN(&(pool->lock), NULL);
|
||||
for (;;) {
|
||||
|
||||
// in attesa di un messaggio, controllo spurious wakeups.
|
||||
while((pool->count == 0) && (!pool->exiting)) {
|
||||
pthread_cond_wait(&(pool->cond), &(pool->lock));
|
||||
|
||||
@ -149,8 +149,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
volatile int quit = 0;
|
||||
sig_atomic_t stopNewConnections = 0; // true to stop new connections
|
||||
sig_atomic_t numberOfConnections = 0;
|
||||
volatile int stopNewConnections = 0; // true to stop new connections
|
||||
volatile int numberOfConnections = 0;
|
||||
|
||||
while(!quit) {
|
||||
// copio il set nella variabile temporanea per la select
|
||||
|
||||
@ -183,14 +183,13 @@ int parser(int len, char *command, queueT *queue, long fd_c, logT* logFileT, pth
|
||||
removeFile(token2, queue, fd_c, logFileT, lock, waiting);
|
||||
goto _parser_end;
|
||||
}
|
||||
|
||||
goto _parser_cleanup; // nessun comando riconosciuto
|
||||
|
||||
_parser_end:
|
||||
free(command);
|
||||
return 0;
|
||||
// se arrivo qui non ho riconosciuto il comando
|
||||
|
||||
_parser_cleanup:
|
||||
free(command);
|
||||
return -1;
|
||||
|
||||
_parser_end:
|
||||
free(command);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,6 +1,20 @@
|
||||
#pragma once
|
||||
#ifndef SERVERWORKER
|
||||
#define SERVERWORKER
|
||||
|
||||
#include <apiFile.h>
|
||||
#include <fileQueue.h>
|
||||
|
||||
// struttura dati che contiene gli argomenti da passare ai worker threads
|
||||
typedef struct struct_thread {
|
||||
long *args;
|
||||
queueT *q; // puntatore alla queue dei file
|
||||
// logT *logFileT; // puntatore alla struct del file di log
|
||||
threadpool_t *pool; // puntatore alla threadpool
|
||||
pthread_mutex_t *lock;
|
||||
waitingT **waiting; // puntatore ai client in attesa di ottenere la lock su un file
|
||||
} threadT;
|
||||
|
||||
// funzione eseguita dal generico Worker del pool di thread
|
||||
void threadF(void *arg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user