From 1256c65f628dfa4f2304180e6b78f98de06ff2a8 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 17 Jun 2021 12:05:03 +0200 Subject: [PATCH] WIP: server commands --- Makefile | 2 +- include/base.h | 6 +++++ src/main.c | 61 -------------------------------------------------- src/server.c | 3 ++- 4 files changed, 9 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 932528c..b9938a2 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ INCDIR=include SRCDIR=src DEBDIR=debian SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/localworker.o \ - $(BINDIR)/centers.o $(BINDIR)/main.o + $(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/main.o CLIOBJ= $(BINDIR)/cli.o .DEFAULT_GOAL:= all diff --git a/include/base.h b/include/base.h index 66da1f6..60dab17 100644 --- a/include/base.h +++ b/include/base.h @@ -114,6 +114,12 @@ struct { // Server // +struct { + const char *name; + void* (*func)(void*); + const char *help; +} typedef Command_t; + struct { pthread_t *id; bool pleaseStop; diff --git a/src/main.c b/src/main.c index c94159d..40f0331 100644 --- a/src/main.c +++ b/src/main.c @@ -24,18 +24,9 @@ #include "../include/scheduler.h" -#define ARROW_NUMBER 150 -#define MAX_CYCLES 15 -#define MAX_THREAD 0 -#define XMAX 1000 -#define YMAX 1000 -#define ZMAX 0 -#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1) - int main(int argc, char **argv) { time_t t; - //Scheduler_t *scheduler0; Server_t *server0; // Go! @@ -47,58 +38,6 @@ int main(int argc, char **argv) t = time(&t); srand((unsigned) t); - // - // Creating structure for the Scheduler - // - /* scheduler0 = (Scheduler_t*) calloc(1, sizeof(Scheduler_t)); */ - - /* scheduler0->globalDrawingSpace = */ - /* (Space_t*) calloc(1, sizeof(Space_t)); */ - /* scheduler0->globalDrawingSpace->space = */ - /* (SpaceUnit_t*) calloc(SPACE_SIZE, sizeof(SpaceUnit_t)); */ - /* scheduler0->globalDrawingSpace->size = SPACE_SIZE; */ - /* scheduler0->globalDrawingSpace->xmax = SPACE_SIZE; */ - /* scheduler0->globalDrawingSpace->ymax = SPACE_SIZE; */ - /* scheduler0->globalDrawingSpace->zmax = SPACE_SIZE; */ - - /* scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); */ - /* scheduler0->arrowList->array = */ - /* (Arrow_t*) calloc(ARROW_NUMBER, sizeof(Arrow_t)); */ - /* scheduler0->arrowList->size = ARROW_NUMBER; */ - - /* printLog("Populating a random arrow list...\n"); */ - /* for (int i = 0; i < ARROW_NUMBER; i++) { */ - - /* if (scheduler0->globalDrawingSpace->xmax) */ - /* scheduler0->arrowList->array[i].x = */ - /* rand() % (scheduler0->globalDrawingSpace->xmax + 1); */ - - /* if (scheduler0->globalDrawingSpace->ymax) */ - /* scheduler0->arrowList->array[i].y = */ - /* rand() % (scheduler0->globalDrawingSpace->ymax + 1); */ - - /* if (scheduler0->globalDrawingSpace->zmax) */ - /* scheduler0->arrowList->array[i].z = */ - /* rand() % (scheduler0->globalDrawingSpace->zmax + 1); */ - /* } */ - - /* scheduler0->nmaxThread = MAX_THREAD; */ - /* scheduler0->nmaxCycles = MAX_CYCLES; */ - - /* // */ - /* // Creating the Scheduler thread */ - /* // */ - /* SchedInit(scheduler0); */ - - /* SchedWait(scheduler0); */ - - /* SchedDestroy(scheduler0); */ - - /* free(scheduler0); */ - - // - // Creating structure for the server - // server0 = (Server_t*) calloc(1, sizeof(Server_t)); ServerInit(server0); diff --git a/src/server.c b/src/server.c index f2acea4..8987615 100644 --- a/src/server.c +++ b/src/server.c @@ -20,6 +20,7 @@ //=-------------------------------------------------------------------------=// #include "../include/base.h" +#include "../include/cmds.h" #include #include @@ -82,9 +83,9 @@ static void *serverMain(void *server) Server_t *args; int socketDescriptor, effectiveSocket, clientLen; struct sockaddr_in client; - char clientRequest[255]= {0}; char serverAnswer[255] = {0}; + const char *pMessage = "hello"; // Get args