From 4214fc2502fa3b4b4027a4e9eeab2af1a30dd8b7 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 13 Mar 2024 20:10:10 +0200 Subject: [PATCH] WIP: ready to work --- .gitignore | 2 + Makefile | 22 +- data/models/dimers random walk.xml | 118 +++++++ data/models/dimers_random_walk_recursif.xml | 145 ++++++++ data/schemas/models_0.2.1.xmls | 194 +++++++++++ data/schemas/models_0_recursif.2.1.xmls | 235 +++++++++++++ include/base.h | 27 +- include/cmds.h | 28 +- include/model.h | 22 +- include/parsing.h | 39 --- include/scheduler.h | 54 +-- include/server.h | 2 +- include/supervisor.h | 10 +- include/worker.h | 20 +- src/main.c | 28 +- src/model.c | 10 +- src/server.c | 368 ++++++++++---------- 17 files changed, 995 insertions(+), 329 deletions(-) create mode 100644 data/models/dimers random walk.xml create mode 100644 data/models/dimers_random_walk_recursif.xml create mode 100644 data/schemas/models_0.2.1.xmls create mode 100644 data/schemas/models_0_recursif.2.1.xmls delete mode 100644 include/parsing.h diff --git a/.gitignore b/.gitignore index 53d923c..8925ba7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.o *.deb bin/** +build/** + diff --git a/Makefile b/Makefile index a566609..71ecf5b 100644 --- a/Makefile +++ b/Makefile @@ -39,10 +39,11 @@ NTHREADS= $(shell nproc) CC=gcc WARNINGS= -Wall -DEBUG= -ggdb -fno-omit-frame-pointer -fdiagnostics-color=always -fsanitize=bounds -fstack-check - #-fsanitize=address \ - #-fsanitize=pointer-compare -fsanitize=pointer-subtract \ - #-fsanitize=leak -fsanitize=undefined -fsanitize=null -fsanitize=bounds +DEBUG= -ggdb -fno-omit-frame-pointer -fdiagnostics-color=always \ + -fsanitize=bounds -fstack-check -fopenmp \ + -fsanitize=address \ + -fsanitize=pointer-compare -fsanitize=pointer-subtract \ + -fsanitize=leak -fsanitize=undefined -fsanitize=null -fsanitize=bounds OPTIMIZE= -O3 INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4) LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW @@ -112,8 +113,7 @@ build_system: run: build_system @echo -e ${CL2}[$@] ${CL}executing...${CL3} - @gdb bin/gem-graph-server \ - -ex "set args -C debian/etc -M debian/var/models -U debian/var/users" + @bin/gem-graph-server -C data/config -M data/models -U data/users @echo -e ${CL2}[$@] ${CL}done.${CL3} debug: build_system @@ -124,19 +124,17 @@ debug: build_system valgrind: build_system @echo -e ${CL2}[$@] ${CL}executing...${CL3} @valgrind --leak-check=full --show-leak-kinds=all -s \ - bin/gem-graph-server -C debian/etc -M debian/var/models \ - -U debian/var/users + bin/gem-graph-server -C data/config -M data/models -U data/users @echo -e ${CL2}[$@] ${CL}done.${CL3} run-both: build_system @echo -e ${CL2}[$@] ${CL}executing...${CL3} - @bin/gem-graph-server -C debian/etc -M debian/var/models \ - -U debian/var/users & sleep 1 && bin/gem-graph-ctl + @bin/gem-graph-server -C data/config -M data/models -U data/users\ + & sleep 1 && bin/gem-graph-ctl @echo -e ${CL2}[$@] ${CL}done.${CL3} run-server: build_system @echo -e ${CL2}[$@] ${CL}executing...${CL3} - @bin/gem-graph-server -C debian/etc -M debian/var/models \ - -U debian/var/users + @bin/gem-graph-server -C data/config -M data/models -U data/users @echo -e ${CL2}[$@] ${CL}done.${CL3} all: build_system diff --git a/data/models/dimers random walk.xml b/data/models/dimers random walk.xml new file mode 100644 index 0000000..12ae465 --- /dev/null +++ b/data/models/dimers random walk.xml @@ -0,0 +1,118 @@ + + + + + Modèle de test + + Léontine Patinette + + 2 + + 1630000000 + + 1.0 + + Ref + + + + + 0 + 9 + + + + + + + + + + + + + + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/models/dimers_random_walk_recursif.xml b/data/models/dimers_random_walk_recursif.xml new file mode 100644 index 0000000..0bd387c --- /dev/null +++ b/data/models/dimers_random_walk_recursif.xml @@ -0,0 +1,145 @@ + + + + + Test 21-03-2023 + + J + + J + + time_stamp + + 1.0 + + Ref + + + + + 0 + 9 + + + + + + + + + + + + + + + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/schemas/models_0.2.1.xmls b/data/schemas/models_0.2.1.xmls new file mode 100644 index 0000000..3a623f5 --- /dev/null +++ b/data/schemas/models_0.2.1.xmls @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/schemas/models_0_recursif.2.1.xmls b/data/schemas/models_0_recursif.2.1.xmls new file mode 100644 index 0000000..3714f41 --- /dev/null +++ b/data/schemas/models_0_recursif.2.1.xmls @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/base.h b/include/base.h index 8dec1f9..4302918 100644 --- a/include/base.h +++ b/include/base.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -35,13 +36,29 @@ /* -------------------------------------------------------------------------- */ -#define LOGMSG "[%s]" -#define printLog(FORMAT, ...) printf("\e[0m" LOGMSG " " FORMAT "\e[0m", \ - __func__, ##__VA_ARGS__) -#define printErr(FORMAT,...) fprintf(stderr, "\e[0m" LOGMSG " " FORMAT "\e[0m",\ - __func__, ##__VA_ARGS__) +#define LOGMSG "<%s:%s()>" +#define printlog(FORMAT, ...) printf("\e[0m" LOGMSG " " FORMAT "\e[0m", \ + __FILE__,__func__, ##__VA_ARGS__) +#define printerr(FORMAT,...) fprintf(stderr, "\e[0m" LOGMSG " " FORMAT "\e[0m",\ + __FILE__,__func__, ##__VA_ARGS__) #define LEN(x) (sizeof(x) / sizeof((x)[0])) /* -------------------------------------------------------------------------- */ +struct parameters_t +{ + char *configDir; + char *userDir; + char *modelDir; +}; +/* + * Structure describing an arrow + */ +struct arrow_t { + uint load; + uint site; + uint x; + uint y; + uint z; +}; diff --git a/include/cmds.h b/include/cmds.h index f5e6293..8c0fe70 100644 --- a/include/cmds.h +++ b/include/cmds.h @@ -32,26 +32,26 @@ /* -------------------------------------------------------------------------- */ -struct command_t { - const char *name; - char* (*execute)(char*, char**, Server_t*); - const char *help; -} typedef command_t; +// struct command_t { +// const char *name; +// char* (*execute)(char*, char**, Server_t*); +// const char *help; +// } typedef command_t; /* -------------------------------------------------------------------------- */ // // Existing commands // -char *Cmd_model(char*, char**, Server_t*); -char *cmd_shutdown(char*, char**, Server_t*); -char *cmd_help(char*, char**, Server_t*); +// char *Cmd_model(char*, char**, Server_t*); +// char *cmd_shutdown(char*, char**, Server_t*); +// char *cmd_help(char*, char**, Server_t*); -static command_t cmdList[] = -{ - {"help", cmd_help, "Help command"}, - {"model", cmd_model, "Model command"}, - {"shutdown", cmd_shutdown, "Shutdown command"}, -}; +// static command_t cmdList[] = +// { +// {"help", cmd_help, "Help command"}, +// {"model", cmd_model, "Model command"}, +// {"shutdown", cmd_shutdown, "Shutdown command"}, +// }; /* -------------------------------------------------------------------------- */ diff --git a/include/model.h b/include/model.h index 42d2946..372387a 100644 --- a/include/model.h +++ b/include/model.h @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include /* -------------------------------------------------------------------------- */ @@ -51,44 +51,44 @@ // -------------------------------------------------------------------------- // // Model init function (and model discovery) // // -------------------------------------------------------------------------- // -void model_system_init (parameters_t *parameters); +// void model_system_init (parameters_t *parameters); // -------------------------------------------------------------------------- // // Model stopping function // // -------------------------------------------------------------------------- // -void model_system_shutdown (void); +// void model_system_shutdown (void); // -------------------------------------------------------------------------- // // Load a model ready to execute // // -------------------------------------------------------------------------- // -int model_load (int id); +// int model_load (int id); // -------------------------------------------------------------------------- // // Unload a model // // -------------------------------------------------------------------------- // -int model_unload (int id); +// int model_unload (int id); // -------------------------------------------------------------------------- // // Add a model to the known model list // // -------------------------------------------------------------------------- // -void model_add_to_known (model_t **newModel); +// void model_add_to_known (model_t **newModel); // -------------------------------------------------------------------------- // // Print informations about all models (known and loaded) to the client // // -------------------------------------------------------------------------- // -void print_models (char *buf); +// void print_models (char *buf); // -------------------------------------------------------------------------- // // Launch a model execution // // -------------------------------------------------------------------------- // -int model_run (int id); +// int model_run (int id); // -------------------------------------------------------------------------- // // Stop a model execution // // -------------------------------------------------------------------------- // -int model_stop (int id); +// int model_stop (int id); // -------------------------------------------------------------------------- // // Stop and unload all loaded or running model // // -------------------------------------------------------------------------- // -void model_shutdown (void); +// void model_shutdown (void); diff --git a/include/parsing.h b/include/parsing.h deleted file mode 100644 index 06e9ec0..0000000 --- a/include/parsing.h +++ /dev/null @@ -1,39 +0,0 @@ -//=-------------------------------------------------------------------------=// -// XML parsing module // -// // -// Copyright © 2021 Libre en Communs (contact@a-lec.org) // -// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) // -// // -// This file is part of gem-graph. // -// // -// This program is free software: you can redistribute it and/or modify // -// it under the terms of the GNU Affero General Public License as // -// published by the Free Software Foundation, either version 3 of the // -// License, or (at your option) any later version. // -// // -// This program is distributed in the hope that it will be useful, // -// but WITHOUT ANY WARRANTY; without even the implied warranty of // -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // -// GNU Affero General Public License for more details. // -// // -// You should have received a copy of the GNU Affero General Public License // -// along with this program. If not, see . // -//=-------------------------------------------------------------------------=// - -#pragma once -#ifndef BASE_H - #include "../include/base.h" -#endif - -#include -#include -#include -#include - -/* -------------------------------------------------------------------------- */ - -#define NO_DESTINATION NULL - -/* -------------------------------------------------------------------------- */ - - diff --git a/include/scheduler.h b/include/scheduler.h index 0985ce1..449a5e8 100644 --- a/include/scheduler.h +++ b/include/scheduler.h @@ -32,40 +32,40 @@ // -------------------------------------------------------------------------- // // Scheduler init function // // -------------------------------------------------------------------------- // -void sched_init(scheduler_t *scheduler); +//void sched_init(scheduler_t *scheduler); // -------------------------------------------------------------------------- // // Scheduler content destructor function // // -------------------------------------------------------------------------- // -static inline void sched_clean (scheduler_t *scheduler) -{ - assert(scheduler); +// static inline void sched_clean (scheduler_t *scheduler) +// { +// assert(scheduler); - if (scheduler->globalDrawingSpace) { - if (scheduler->globalDrawingSpace->space) { - free(scheduler->globalDrawingSpace->space); - scheduler->globalDrawingSpace->space = NULL; - } - free(scheduler->globalDrawingSpace); - scheduler->globalDrawingSpace = NULL; - } +// if (scheduler->globalDrawingSpace) { +// if (scheduler->globalDrawingSpace->space) { +// free(scheduler->globalDrawingSpace->space); +// scheduler->globalDrawingSpace->space = NULL; +// } +// free(scheduler->globalDrawingSpace); +// scheduler->globalDrawingSpace = NULL; +// } - if (scheduler->arrowArray) { - if (scheduler->arrowArray->array) { - free(scheduler->arrowArray->array); - scheduler->arrowArray->array = NULL; - } - free(scheduler->arrowArray); - scheduler->arrowArray = NULL; - } -} +// if (scheduler->arrowArray) { +// if (scheduler->arrowArray->array) { +// free(scheduler->arrowArray->array); +// scheduler->arrowArray->array = NULL; +// } +// free(scheduler->arrowArray); +// scheduler->arrowArray = NULL; +// } +// } // -------------------------------------------------------------------------- // // Scheduler destructor function // // -------------------------------------------------------------------------- // -static inline void sched_shutdown (scheduler_t *scheduler) -{ - assert(scheduler); - free(scheduler); - scheduler = NULL; -} +// static inline void sched_shutdown (scheduler_t *scheduler) +// { +// assert(scheduler); +// free(scheduler); +// scheduler = NULL; +// } diff --git a/include/server.h b/include/server.h index 92e53a3..6fb2137 100644 --- a/include/server.h +++ b/include/server.h @@ -37,4 +37,4 @@ // -------------------------------------------------------------------------- // // Server init function // // -------------------------------------------------------------------------- // -void server_init (server_t *server); +//void server_init (server_t *server); diff --git a/include/supervisor.h b/include/supervisor.h index 144d296..8a9630b 100644 --- a/include/supervisor.h +++ b/include/supervisor.h @@ -30,12 +30,12 @@ // -------------------------------------------------------------------------- // // Supervisor init function // // -------------------------------------------------------------------------- // -void superv_init (supervisor_t *supervisor); +//void superv_init (supervisor_t *supervisor); // -------------------------------------------------------------------------- // // Supervisor destructor function // // -------------------------------------------------------------------------- // -static inline void superv_destroy (supervisor_t *supervisor) -{ - ; -} +// static inline void superv_destroy (supervisor_t *supervisor) +// { +// ; +// } diff --git a/include/worker.h b/include/worker.h index bee79c6..1bdd01b 100644 --- a/include/worker.h +++ b/include/worker.h @@ -30,18 +30,18 @@ // -------------------------------------------------------------------------- // // Worker init function // // -------------------------------------------------------------------------- // -void worker_init(worker_t *worker); +//void worker_init(worker_t *worker); // -------------------------------------------------------------------------- // // Worker destructor function // // -------------------------------------------------------------------------- // -static inline void worker_destroy(worker_t *worker) -{ - worker->pleaseStop = false; - worker->terminated = false; - worker->returnValue = false; +// static inline void worker_destroy(worker_t *worker) +// { +// worker->pleaseStop = false; +// worker->terminated = false; +// worker->returnValue = false; - worker->id = 0; - free(worker->localWorkAreaCenter); - worker->localWorkAreaCenter = NULL; -} +// worker->id = 0; +// free(worker->localWorkAreaCenter); +// worker->localWorkAreaCenter = NULL; +// } diff --git a/src/main.c b/src/main.c index 2c004dd..272f55e 100644 --- a/src/main.c +++ b/src/main.c @@ -26,15 +26,15 @@ /* -------------------------------------------------------------------------- */ -static server_t *server; +/* static server_t *server; */ /* static void sig_term_handler(int signum) */ /* { */ /* server->pleaseStop = true; */ -/* printLog("Server stopping\n"); */ +/* printlog("Server stopping\n"); */ /* //XXX ModelShutdown(); */ -/* printLog("All model shutted down\n"); */ +/* printlog("All model shutted down\n"); */ /* } */ int main(int argc, char **argv) @@ -42,27 +42,27 @@ int main(int argc, char **argv) int options; time_t t; int returnValue = 0; - parameters_t parameters; + struct parameters_t parameters = {0}; while ((options = getopt(argc, argv, ":C:M:U:")) != -1) { switch (options) { case 'C': - printLog("Config : %s\n", optarg); + printlog("Config : %s\n", optarg); parameters.configDir = calloc(1, strlen(optarg) + 1); strcpy(parameters.configDir, optarg); break; case 'M': - printLog("Models : %s\n", optarg); + printlog("Models : %s\n", optarg); parameters.modelDir = calloc(1, strlen(optarg) + 1); strcpy(parameters.modelDir, optarg); break; case 'U': - printLog("Users : %s\n", optarg); + printlog("Users : %s\n", optarg); parameters.userDir = calloc(1, strlen(optarg) + 1); strcpy(parameters.userDir, optarg); break; case ':': - printErr("Option missing argument : %c\n", optopt); + printerr("Option missing argument : %c\n", optopt); if (parameters.configDir) free(parameters.configDir); @@ -75,7 +75,7 @@ int main(int argc, char **argv) return ENOSYS; break; case '?': - printErr("Unknown option : %c\n", optopt); + printerr("Unknown option : %c\n", optopt); if (parameters.configDir) free(parameters.configDir); @@ -91,7 +91,7 @@ int main(int argc, char **argv) } if (!parameters.configDir | !parameters.modelDir | !parameters.userDir) { - printErr("Missing arguments\n"); + printerr("Missing arguments\n"); if (parameters.configDir) free(parameters.configDir); @@ -106,15 +106,15 @@ int main(int argc, char **argv) } // Go! - printLog("Starting gem-graph-server...\n"); + printlog("Starting gem-graph-server...\n"); /* // Register new interrupt handler */ /* signal(SIGINT, sig_term_handler); */ /* signal(SIGTERM, sig_term_handler); */ - /* // Initializing random generator */ - /* t = time(&t); */ - /* srand((unsigned) t); */ + // Initializing random generator + t = time(&t); + srand((unsigned)t); /* server = calloc(1, sizeof(*server)); */ diff --git a/src/model.c b/src/model.c index fb2ddae..ecd50ae 100644 --- a/src/model.c +++ b/src/model.c @@ -21,7 +21,6 @@ //=-------------------------------------------------------------------------=// #include "../include/model.h" -#include "../include/parsing.h" #include "../include/arrows.h" #include "../include/scheduler.h" @@ -57,13 +56,13 @@ bool model_init(const char *content, size_t length, const char *basename) node = xmlDocGetRootElement(model); if (node == NULL) { - g_printerr("Empty XML model !\n"); + fprintf(stderr, "Empty XML model !\n"); xmlFreeDoc(model); return false; } if (xmlStrcmp(node->name, (xmlChar *) "gem-graph-model")) { - g_printerr("document of the wrong type, root node != gem-graph-model\n"); + fprintf(stderr, "document of the wrong type, root node != gem-graph-model\n"); xmlFreeDoc(model); return false; } @@ -71,7 +70,7 @@ bool model_init(const char *content, size_t length, const char *basename) model_hashtable = xmlHashCreate(0); if (model_hashtable == NULL) { - g_printerr("Can't create model hash table !\n"); + fprintf(stderr, "Can't create model hash table !\n"); xmlFreeDoc(model); return false; } @@ -117,9 +116,6 @@ static inline xmlChar* getFirstTag(xmlChar *path) path = (xmlChar *)xmlStrchr(path, '/'); path = xmlStrsub (path, 1, xmlStrlen(path)); - //printf("%s = %s + / + %s\n", preop,\ - xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1), path); - return xmlStrsub (preop, 0, xmlStrlen(preop) - xmlStrlen(path) - 1); } diff --git a/src/server.c b/src/server.c index a82fc68..9b89ffa 100644 --- a/src/server.c +++ b/src/server.c @@ -25,223 +25,223 @@ /* -------------------------------------------------------------------------- */ -static void *server_main(void *server); +/* static void *server_main(void *server); */ /* -------------------------------------------------------------------------- */ -#define SEND_BUFFER_SIZE 80 * 24 -#define RECEIVE_BUFFER_SIZE 80 -void *server_communication_instance(void *serverCom) -{ - servercom_t *args; - char **argv = NULL; - char receiveBuff[RECEIVE_BUFFER_SIZE]; - char sendBuff[SEND_BUFFER_SIZE]; - int tokenIndex, bytesReceived, clientPort; - char clientIP[16]; +/* #define SEND_BUFFER_SIZE 80 * 24 */ +/* #define RECEIVE_BUFFER_SIZE 80 */ +/* void *server_communication_instance(void *serverCom) */ +/* { */ +/* servercom_t *args; */ +/* char **argv = NULL; */ +/* char receiveBuff[RECEIVE_BUFFER_SIZE]; */ +/* char sendBuff[SEND_BUFFER_SIZE]; */ +/* int tokenIndex, bytesReceived, clientPort; */ +/* char clientIP[16]; */ - args = (servercom_t*) serverCom; +/* args = (servercom_t*) serverCom; */ - // Get ip address from client - inet_ntop(AF_INET, - &args->clientAddr.sin_addr, - clientIP, - args->sockLen); +/* // Get ip address from client */ +/* inet_ntop(AF_INET, */ +/* &args->clientAddr.sin_addr, */ +/* clientIP, */ +/* args->sockLen); */ - // Get port number from client - clientPort = ntohs(args->clientAddr.sin_port); +/* // Get port number from client */ +/* clientPort = ntohs(args->clientAddr.sin_port); */ - //Accept and incoming connection - while(!args->pleaseStop) { +/* //Accept and incoming connection */ +/* while(!args->pleaseStop) { */ - // Zeroing buffer - bzero(receiveBuff, RECEIVE_BUFFER_SIZE); - //printLog("Waiting for commands...\n"); +/* // Zeroing buffer */ +/* bzero(receiveBuff, RECEIVE_BUFFER_SIZE); */ +/* //printLog("Waiting for commands...\n"); */ - // Read the message from client and copy it in buffer - bytesReceived = recv(args->sockfd, receiveBuff, RECEIVE_BUFFER_SIZE, 0); - if (bytesReceived == -1) { - printErr("Could not receive data! (%s)\n", strerror(errno)); - break; - }; +/* // Read the message from client and copy it in buffer */ +/* bytesReceived = recv(args->sockfd, receiveBuff, RECEIVE_BUFFER_SIZE, 0); */ +/* if (bytesReceived == -1) { */ +/* printErr("Could not receive data! (%s)\n", strerror(errno)); */ +/* break; */ +/* }; */ - // Ignore null-sized request - if (bytesReceived == 0) - break; +/* // Ignore null-sized request */ +/* if (bytesReceived == 0) */ +/* break; */ - // Print buffer which contains the client request - printLog("Client %s:%d request : '%s'\n", - clientIP, - clientPort, - receiveBuff); +/* // Print buffer which contains the client request */ +/* printLog("Client %s:%d request : '%s'\n", */ +/* clientIP, */ +/* clientPort, */ +/* receiveBuff); */ - if (receiveBuff[0] == '\0') //XXX - break; +/* if (receiveBuff[0] == '\0') //XXX */ +/* break; */ - // get args in an array - tokenIndex = 0; - argv = (char**) realloc(argv, 1 * sizeof(char*)); - argv[0] = strtok(receiveBuff, " "); - while (argv[tokenIndex]) { - tokenIndex++; - argv = (char**) realloc(argv, (tokenIndex+1) * sizeof(char*)); - argv[tokenIndex] = strtok(NULL, " "); - } +/* // get args in an array */ +/* tokenIndex = 0; */ +/* argv = (char**) realloc(argv, 1 * sizeof(char*)); */ +/* argv[0] = strtok(receiveBuff, " "); */ +/* while (argv[tokenIndex]) { */ +/* tokenIndex++; */ +/* argv = (char**) realloc(argv, (tokenIndex+1) * sizeof(char*)); */ +/* argv[tokenIndex] = strtok(NULL, " "); */ +/* } */ - // Zeroing buffer - bzero(sendBuff, RECEIVE_BUFFER_SIZE); +/* // Zeroing buffer */ +/* bzero(sendBuff, RECEIVE_BUFFER_SIZE); */ - // Execute command by first arg in cmdList - for (int i = 0; i < LEN(cmdList); i++) { - if (strcmp(cmdList[i].name, argv[0]) == 0) { - cmdList[i].execute(sendBuff, argv, args->associatedServer); - } - } +/* // Execute command by first arg in cmdList */ +/* for (int i = 0; i < LEN(cmdList); i++) { */ +/* if (strcmp(cmdList[i].name, argv[0]) == 0) { */ +/* cmdList[i].execute(sendBuff, argv, args->associatedServer); */ +/* } */ +/* } */ - // and send that buffer to client - send(args->sockfd, sendBuff, SEND_BUFFER_SIZE, 0); - } +/* // and send that buffer to client */ +/* send(args->sockfd, sendBuff, SEND_BUFFER_SIZE, 0); */ +/* } */ - close(args->sockfd); - if (argv) { - free(argv); - argv = NULL; - } - printLog("Disconnected from %s:%d\n", clientIP, clientPort); - return NULL; -} +/* close(args->sockfd); */ +/* if (argv) { */ +/* free(argv); */ +/* argv = NULL; */ +/* } */ +/* printLog("Disconnected from %s:%d\n", clientIP, clientPort); */ +/* return NULL; */ +/* } */ -// -------------------------------------------------------------------------- // -// Server main function // -// -------------------------------------------------------------------------- // -#define PORT 9000 -#define MAX_CONNECTION 100 +/* // -------------------------------------------------------------------------- // */ +/* // Server main function // */ +/* // -------------------------------------------------------------------------- // */ +/* #define PORT 9000 */ +/* #define MAX_CONNECTION 100 */ -static void *server_main(void *server) -{ - Server_t *args; - ServerCommunication_t serverSlots[MAX_CONNECTION] = {0}; - int connfd, flags, threadStatus, serverSlotIndex = 0; - uint socklen; - struct sockaddr_in servaddr; - char clientIP[16]; +/* static void *server_main(void *server) */ +/* { */ +/* Server_t *args; */ +/* ServerCommunication_t serverSlots[MAX_CONNECTION] = {0}; */ +/* int connfd, flags, threadStatus, serverSlotIndex = 0; */ +/* uint socklen; */ +/* struct sockaddr_in servaddr; */ +/* char clientIP[16]; */ - // Get args - args = (Server_t*) server; - args->returnValue = 0; - printLog("Server #%lu online\n", args->id); +/* // Get args */ +/* args = (Server_t*) server; */ +/* args->returnValue = 0; */ +/* printLog("Server #%lu online\n", args->id); */ - // Create socket - args->sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (args->sockfd == -1) { - printErr("Socket creation failed! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Create socket */ +/* args->sockfd = socket(AF_INET, SOCK_STREAM, 0); */ +/* if (args->sockfd == -1) { */ +/* printErr("Socket creation failed! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - // Get socket flags - flags = fcntl(args->sockfd, F_GETFL); - if (flags == -1) { - printErr("Socket parameters getting failed! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Get socket flags */ +/* flags = fcntl(args->sockfd, F_GETFL); */ +/* if (flags == -1) { */ +/* printErr("Socket parameters getting failed! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - // Change socket flags to non-blocking - if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) { - printErr("Socket non-blocking setting failed! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Change socket flags to non-blocking */ +/* if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) { */ +/* printErr("Socket non-blocking setting failed! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - // Prepare binding structure - bzero(&servaddr, sizeof(servaddr)); +/* // Prepare binding structure */ +/* bzero(&servaddr, sizeof(servaddr)); */ - // Assign IP and PORT - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(PORT); +/* // Assign IP and PORT */ +/* servaddr.sin_family = AF_INET; */ +/* servaddr.sin_addr.s_addr = htonl(INADDR_ANY); */ +/* servaddr.sin_port = htons(PORT); */ - // Binding newly created socket - if ((bind(args->sockfd, (struct sockaddr*)&servaddr, - sizeof(servaddr))) == -1) { - printErr("Socket bind failed! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Binding newly created socket */ +/* if ((bind(args->sockfd, (struct sockaddr*)&servaddr, */ +/* sizeof(servaddr))) == -1) { */ +/* printErr("Socket bind failed! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - // Now server is ready to listen and verification - if (listen(args->sockfd, MAX_CONNECTION) == -1) { - printErr("Socket listening failed! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Now server is ready to listen and verification */ +/* if (listen(args->sockfd, MAX_CONNECTION) == -1) { */ +/* printErr("Socket listening failed! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - socklen = sizeof(struct sockaddr_in); +/* socklen = sizeof(struct sockaddr_in); */ - // Get server socket address structure - if (getsockname(args->sockfd, (struct sockaddr *)&servaddr, &socklen) - == -1) { - printErr("Could not get socket structure! (%s)\n", strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Get server socket address structure */ +/* if (getsockname(args->sockfd, (struct sockaddr *)&servaddr, &socklen) */ +/* == -1) { */ +/* printErr("Could not get socket structure! (%s)\n", strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - printLog("Server listening...\n"); +/* printLog("Server listening...\n"); */ - while (!args->pleaseStop) { +/* while (!args->pleaseStop) { */ - // Accept the data packet from client - connfd = accept(args->sockfd, - (struct sockaddr*) &serverSlots[serverSlotIndex].clientAddr, - &socklen); - if (connfd < 0) { - // If error is not due to lack of clients connecting, this is error - if (errno != EWOULDBLOCK && errno != EAGAIN) { - printErr("Server acccept failed! (%s)\n", strerror(errno)); - goto serverExiting; - } - sleep(1); - } else { - // Client connected - // get IP addr from client - inet_ntop(AF_INET, - &(serverSlots[serverSlotIndex].clientAddr.sin_addr), - clientIP, socklen); - printLog("Client accepted from %s:%d\n", - clientIP, - ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread +/* // Accept the data packet from client */ +/* connfd = accept(args->sockfd, */ +/* (struct sockaddr*) &serverSlots[serverSlotIndex].clientAddr, */ +/* &socklen); */ +/* if (connfd < 0) { */ +/* // If error is not due to lack of clients connecting, this is error */ +/* if (errno != EWOULDBLOCK && errno != EAGAIN) { */ +/* printErr("Server acccept failed! (%s)\n", strerror(errno)); */ +/* goto serverExiting; */ +/* } */ +/* sleep(1); */ +/* } else { */ +/* // Client connected */ +/* // get IP addr from client */ +/* inet_ntop(AF_INET, */ +/* &(serverSlots[serverSlotIndex].clientAddr.sin_addr), */ +/* clientIP, socklen); */ +/* printLog("Client accepted from %s:%d\n", */ +/* clientIP, */ +/* ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread */ - // Populate communicator slot - serverSlots[serverSlotIndex].sockLen = socklen; // XXX - serverSlots[serverSlotIndex].sockfd = connfd; - serverSlots[serverSlotIndex].associatedServer = args; +/* // Populate communicator slot */ +/* serverSlots[serverSlotIndex].sockLen = socklen; // XXX */ +/* serverSlots[serverSlotIndex].sockfd = connfd; */ +/* serverSlots[serverSlotIndex].associatedServer = args; */ - // Create thread - threadStatus = pthread_create(&serverSlots[serverSlotIndex].id, - NULL, - server_communication_instance, - (void*)&serverSlots[serverSlotIndex]); - if(threadStatus != 0) { - printErr("Error from pthread: %d (%s)\n", - threadStatus, strerror(errno)); - args->returnValue = 1; - goto serverExiting; - } +/* // Create thread */ +/* threadStatus = pthread_create(&serverSlots[serverSlotIndex].id, */ +/* NULL, */ +/* server_communication_instance, */ +/* (void*)&serverSlots[serverSlotIndex]); */ +/* if(threadStatus != 0) { */ +/* printErr("Error from pthread: %d (%s)\n", */ +/* threadStatus, strerror(errno)); */ +/* args->returnValue = 1; */ +/* goto serverExiting; */ +/* } */ - serverSlotIndex++; - //printLog("Accepted connection. Server will now listen...\n"); - } - } +/* serverSlotIndex++; */ +/* //printLog("Accepted connection. Server will now listen...\n"); */ +/* } */ +/* } */ -serverExiting: - for (int i; i < serverSlotIndex; i++) { - serverSlots[i].pleaseStop = true; - usleep(10000); - pthread_cancel(serverSlots[i].id); - pthread_join(serverSlots[i].id, NULL); - } - close(args->sockfd); - printLog("Server #%lu offline\n", args->id); - return NULL; -} +/* serverExiting: */ +/* for (int i; i < serverSlotIndex; i++) { */ +/* serverSlots[i].pleaseStop = true; */ +/* usleep(10000); */ +/* pthread_cancel(serverSlots[i].id); */ +/* pthread_join(serverSlots[i].id, NULL); */ +/* } */ +/* close(args->sockfd); */ +/* printLog("Server #%lu offline\n", args->id); */ +/* return NULL; */ +/* } */