Fixed makefile
This commit is contained in:
46
src/server.c
46
src/server.c
@ -62,8 +62,9 @@ int main(int argc, char *argv[]) {
|
||||
int pendingSize; CONFGETINT(pendingSize, config, "threadpool", "pending", NULL, 10);
|
||||
int maxFiles; CONFGETINT(maxFiles, config, "files", "MaxFiles", NULL, 10);
|
||||
int maxSize; CONFGETINT(maxSize, config, "files", "MaxSize", NULL, 10);
|
||||
char *logFile, *buf; CONFGETSTR(logFile, config, "log", "logFile", buf);
|
||||
char *socketName, *buf; CONFGETSTR(socketName, config, "socket", "name", buf);
|
||||
const char *buff;
|
||||
char *logFile; CONFGETSTR(logFile, config, "log", "logFile", buff);
|
||||
char *socketName; CONFGETSTR(socketName, config, "socket", "name", buff);
|
||||
int maxBacklog; CONFGETINT(maxBacklog, config, "socket", "backlog", NULL, 10);
|
||||
ini_free(config);
|
||||
|
||||
@ -89,12 +90,15 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
// creo la struttura per il log
|
||||
taglia_t *taglia = taglia_init(logFile);
|
||||
taglia_t *taglia = taglia_init(logFile, 0);
|
||||
free(logFile); // free del nome del file
|
||||
if(taglia==NULL) {
|
||||
perror("taglia_init");
|
||||
goto _cleanup;
|
||||
}
|
||||
// risorse per il logfile usate nel main
|
||||
char buf[2048];
|
||||
int n;
|
||||
|
||||
|
||||
// pipes di comunicazione fra thread main e sigHandler thread/threadF threads
|
||||
@ -120,10 +124,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// scrivo sul log
|
||||
char buf[2048];
|
||||
int n;
|
||||
n = snprintf(buf, sizeof(buf), "Creato signal thread con id: %l\n", (long) sighandler_thread);
|
||||
if( n<0 || m<n ) {
|
||||
n = snprintf(buf, sizeof(buf), "Creato signal thread con id: %ld\n", (long) sighandler_thread);
|
||||
if( n<0 ) {
|
||||
perror("snprintf");
|
||||
goto _cleanup;
|
||||
}
|
||||
@ -160,8 +162,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// scrivo sul log
|
||||
char buf[2048];
|
||||
int n;
|
||||
n = snprintf(buf, sizeof(buf), "Creato socket: %s\n", socketName);
|
||||
if( n<0 ) {
|
||||
perror("snprintf");
|
||||
@ -187,8 +187,6 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
// scrivo sul log
|
||||
char buf[2048];
|
||||
int n;
|
||||
n = snprintf(buf, sizeof(buf), "Creato threadpool di dimensione %d e lending size %d\n", threadsInPool, pendingSize);
|
||||
if( n<0 ) {
|
||||
perror("snprintf");
|
||||
@ -211,8 +209,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
// scrivo sul log
|
||||
char buf[2048];
|
||||
int n;
|
||||
n = snprintf(buf, sizeof(buf), "File Server ready.\n\tMaxFiles: %d\n\tMaxSize: %d\n", maxFiles, maxSize);
|
||||
if( n<0 ) {
|
||||
perror("snprintf");
|
||||
@ -264,9 +260,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
// scrivo sul log
|
||||
char buf[512];
|
||||
int n;
|
||||
n = snprintf(buf, sizeof(buf), "New client: %l\n", *connfd);
|
||||
n = snprintf(buf, sizeof(buf), "New client: %ld\n", (long) *connfd);
|
||||
if( n<0 ) {
|
||||
perror("snprintf");
|
||||
goto _cleanup;
|
||||
@ -284,8 +278,8 @@ int main(int argc, char *argv[]) {
|
||||
args->connfd = connfd;
|
||||
args->quit = &quit;
|
||||
args->request_pipe = request_pipe[1];
|
||||
args->q = &queue;
|
||||
args->taglia = &taglia;
|
||||
args->q = queue;
|
||||
args->taglia = taglia;
|
||||
args->pool = pool;
|
||||
args->lock = &lock;
|
||||
args->waiting = &waiting;
|
||||
@ -307,7 +301,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
if (i == request_pipe[0]) { // un worker ha finito di servire un client
|
||||
int pdr; // ottengo il descrittore della pipe
|
||||
if (readn(requestPipe[0], &pdr, sizeof(int)) == -1) {
|
||||
if (readn(request_pipe[0], &pdr, sizeof(int)) == -1) {
|
||||
perror("readn");
|
||||
break;
|
||||
}
|
||||
@ -325,7 +319,7 @@ int main(int argc, char *argv[]) {
|
||||
default: // client served but not disconnected
|
||||
FD_SET(pdr, &set);
|
||||
if (pdr > fdmax) {
|
||||
fdmax = fdr;
|
||||
fdmax = pdr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -379,8 +373,8 @@ int main(int argc, char *argv[]) {
|
||||
args->connfd = connfd;
|
||||
args->quit = &quit;
|
||||
args->request_pipe = request_pipe[1];
|
||||
args->q = &queue;
|
||||
args->taglia = &taglia;
|
||||
args->q = queue;
|
||||
args->taglia = taglia;
|
||||
args->pool = pool;
|
||||
args->lock = &lock;
|
||||
args->waiting = &waiting;
|
||||
@ -406,10 +400,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
destroyThreadPool(pool, 0); // notifico che i thread dovranno uscire
|
||||
clearWaiting(&waiting);
|
||||
taglia_stats(taglia); // print stats
|
||||
taglia_stats(taglia, stdout); // print stats
|
||||
|
||||
// print all files in storage during shutdown
|
||||
if (printQueue(queue) == -1) {
|
||||
if (printQueue(stdout, queue) == -1) {
|
||||
perror("printQueue");
|
||||
return 1;
|
||||
}
|
||||
@ -436,7 +430,7 @@ static void *sigHandler(void *arg) {
|
||||
sigset_t *set = ((sigHandler_t*)arg)->set;
|
||||
int fd_pipe = ((sigHandler_t*)arg)->signal_pipe;
|
||||
|
||||
if(pthread_sigmask(SIG_SETMASK, &set, NULL)) {
|
||||
if(pthread_sigmask(SIG_SETMASK, set, NULL)) {
|
||||
fprintf(stderr, "ERROR setting mask\n");
|
||||
return (void*) 1;
|
||||
}
|
||||
@ -444,7 +438,7 @@ static void *sigHandler(void *arg) {
|
||||
while (1) {
|
||||
int sig;
|
||||
int code;
|
||||
int r = sigwait(&set, &sig);
|
||||
int r = sigwait(set, &sig);
|
||||
|
||||
if (r != 0) {
|
||||
errno = r;
|
||||
|
||||
@ -7,8 +7,9 @@
|
||||
|
||||
#include <conn.h>
|
||||
#include <message.h>
|
||||
#include <serverQueue.h>
|
||||
#include <fileQueue.h>
|
||||
#include <apiFile.h>
|
||||
#include <taglialegna.h>
|
||||
|
||||
// funzione eseguita dal Worker thread del pool
|
||||
void threadF(void *arg) {
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
|
||||
// struttura dati che contiene gli argomenti da passare ai worker threads
|
||||
typedef struct struct_thread {
|
||||
int connfd;
|
||||
int *quit;
|
||||
volatile int *quit;
|
||||
int request_pipe;
|
||||
long *connfd;
|
||||
queueT *q; // puntatore alla queue dei file
|
||||
taglia_t *taglia; // 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
|
||||
waiting_t **waiting; // puntatore ai client in attesa di ottenere la lock su un file
|
||||
} threadT;
|
||||
|
||||
// funzione eseguita dal generico Worker del pool di thread
|
||||
|
||||
Reference in New Issue
Block a user