Added log utility and improved server
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <taglialegna.h>
|
||||
#include <fileQueue.h>
|
||||
|
||||
taglia_t *taglia_init(char *file, int n, ...) {
|
||||
int max_files;
|
||||
|
||||
@ -11,7 +11,7 @@ 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;
|
||||
} waiting_t;
|
||||
|
||||
/**
|
||||
* Apri o crea un nuovo file
|
||||
@ -36,25 +36,25 @@ void writeFile(char *filepath, size_t size, queueT *q, long fd_c, logT *logFileT
|
||||
void lockFile(char *filepath, queueT *q, long fd_c, logT *logFileT, pthread_mutex_t *lock, waitingT **waiting);
|
||||
|
||||
// Rilascia una Lock di un file
|
||||
void unlockFile(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, waiting_t **waiting);
|
||||
|
||||
// Chiudi un file
|
||||
void closeFile(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, waiting_t **waiting);
|
||||
|
||||
// Rimuovi un file
|
||||
void removeFile(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, waiting_t **waiting);
|
||||
|
||||
|
||||
// Funzione ausiliaria che invia un file al client
|
||||
int sendFile(fileT *f, long fd_c, logT *logFileT);
|
||||
|
||||
// Aggiunge una coppia client/file alla coda in attesa di ottenere una lock
|
||||
int addWaiting(waitingT **waiting, char *file, int fd);
|
||||
int addWaiting(waiting_t **waiting, char *file, int fd);
|
||||
|
||||
// Ottiene il primo client in attesa su una lock di un determinato file
|
||||
int removeFirstWaiting(waitingT **waiting, char *file);
|
||||
int removeFirstWaiting(waiting_t **waiting, char *file);
|
||||
|
||||
// Distrugge la lista d'attesa e ne libera la memoria
|
||||
void clearWaiting(waitingT **waiting);
|
||||
void clearWaiting(waiting_t **waiting);
|
||||
|
||||
#endif // _API_FILE
|
||||
|
||||
@ -13,9 +13,6 @@
|
||||
#if !defined(BUFSIZE)
|
||||
#define BUFSIZE 256
|
||||
#endif
|
||||
#if !defined(SOCKNAME)
|
||||
#define SOCKNAME "./cs_sock"
|
||||
#endif
|
||||
#if !defined(MAXBACKLOG)
|
||||
#define MAXBACKLOG 32
|
||||
#endif
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <ini.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define CONFGETINT(var, config, t, q, p, base) \
|
||||
@ -14,5 +15,16 @@
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define CONFGETSTR(var, config, t, q, buff) \
|
||||
var = ini_get(config, t, q); \
|
||||
if(var==NULL) { \
|
||||
fprintf(stderr, "ERROR reading config for variable %c\n", t); \
|
||||
ini_free(config); \
|
||||
return 1; \
|
||||
} \
|
||||
buff = calloc(strlen(var)+1, sizeof(char)); \
|
||||
strncpy(buff, var, strlen(var)+1); \
|
||||
var = buff;
|
||||
|
||||
|
||||
#endif /* _SERVER_STATUS */
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
Reference in New Issue
Block a user