Added file queue handling
This commit is contained in:
34
src/server.c
34
src/server.c
@ -13,7 +13,8 @@
|
||||
#include <util.h>
|
||||
#include <serverWorker.h>
|
||||
#include <ini.h>
|
||||
#include <serverStatus.h>
|
||||
#include <serverUtil.h>
|
||||
#include <fileQueue.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -80,7 +81,9 @@ int main(int argc, char *argv[]) {
|
||||
// TODO read config file
|
||||
checkargs(argc, argv);
|
||||
ini_t *config = ini_load(argv[1]);
|
||||
int threadsInPool = (int) strtol(ini_get(config, "threadpool", "quantity"), NULL, 10);
|
||||
int threadsInPool; CONFGETINT(threadsInPool, config, "threadpool", "quantity", NULL, 10);
|
||||
int maxFiles; CONFGETINT(maxFiles, config, "files", "MaxFiles", NULL, 10);
|
||||
int maxSize; CONFGETINT(maxSize, config, "files", "MaxSize", NULL, 10);
|
||||
ini_free(config);
|
||||
|
||||
sigset_t mask;
|
||||
@ -90,7 +93,6 @@ int main(int argc, char *argv[]) {
|
||||
sigaddset(&mask, SIGTERM);
|
||||
|
||||
if (pthread_sigmask(SIG_BLOCK, &mask, NULL) != 0) {
|
||||
// TODO logging utility
|
||||
fprintf(stderr, "ERROR setting mask\n");
|
||||
goto _cleanup;
|
||||
}
|
||||
@ -100,55 +102,57 @@ int main(int argc, char *argv[]) {
|
||||
memset(&s, 0, sizeof(s));
|
||||
s.sa_handler = SIG_IGN;
|
||||
if ( (sigaction(SIGPIPE,&s,NULL)) == -1 ) {
|
||||
// TODO logging utility
|
||||
perror("sigaction");
|
||||
goto _cleanup;
|
||||
}
|
||||
|
||||
/*
|
||||
* La pipe viene utilizzata come canale di comunicazione tra il signal handler thread ed il
|
||||
* thread lisener per notificare la terminazione.
|
||||
* Una alternativa è quella di utilizzare la chiamata di sistema
|
||||
* 'signalfd' ma non e' POSIX.
|
||||
*/
|
||||
printf("File Server ready.");
|
||||
fflush(stdout);
|
||||
|
||||
int signal_pipe[2];
|
||||
if (pipe(signal_pipe) == -1) {
|
||||
// TODO logging utility
|
||||
perror("pipe");
|
||||
goto _cleanup;
|
||||
}
|
||||
|
||||
// todo logging + statistiche
|
||||
|
||||
|
||||
|
||||
pthread_t sighandler_thread;
|
||||
sigHandler_t handlerArgs = { &mask, signal_pipe[1] };
|
||||
if (pthread_create(&sighandler_thread, NULL, sigHandler, &handlerArgs) != 0) {
|
||||
// TODO logging utility
|
||||
fprintf(stderr, "ERROR creating signal handler thread\n");
|
||||
goto _cleanup;
|
||||
}
|
||||
|
||||
int listenfd;
|
||||
if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||
// TODO logging utility
|
||||
perror("socket");
|
||||
goto _cleanup;
|
||||
}
|
||||
|
||||
// thread per i segnali
|
||||
struct sockaddr_un serv_addr;
|
||||
memset(&serv_addr, '0', sizeof(serv_addr));
|
||||
serv_addr.sun_family = AF_UNIX;
|
||||
strncpy(serv_addr.sun_path, SOCKNAME, strlen(SOCKNAME)+1);
|
||||
|
||||
if (bind(listenfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) == -1) {
|
||||
// TODO logging utility
|
||||
perror("bind");
|
||||
goto _cleanup;
|
||||
}
|
||||
if (listen(listenfd, MAXBACKLOG) == -1) {
|
||||
// TODO logging utility
|
||||
perror("listen");
|
||||
goto _cleanup;
|
||||
}
|
||||
|
||||
// creo la queue
|
||||
queueT *queue = createQueue(maxFiles, maxSize);
|
||||
|
||||
|
||||
|
||||
|
||||
threadpool_t *pool = NULL;
|
||||
|
||||
pool = createThreadPool(threadsInPool, threadsInPool);
|
||||
|
||||
Reference in New Issue
Block a user