From ca7cb9294db5986715edf943d7255b2bb553d550 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 8 Jul 2021 18:35:14 +0200 Subject: [PATCH] WIP: Rollback threaded server --- include/base.h | 4 ++-- src/server.c | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/base.h b/include/base.h index 6e59cac..040fa98 100644 --- a/include/base.h +++ b/include/base.h @@ -125,9 +125,9 @@ struct { } typedef Server_t; struct { - pthread_t *id; + pthread_t id; bool pleaseStop; - int socketfd; + int sockfd; } typedef ServerCommunication_t; /* -------------------------------------------------------------------------- */ diff --git a/src/server.c b/src/server.c index 85a04b0..1bf7a71 100644 --- a/src/server.c +++ b/src/server.c @@ -31,7 +31,7 @@ static void *serverMain(void *server); /* -------------------------------------------------------------------------- */ // -------------------------------------------------------------------------- // -// Server init function // +// Server init function // // -------------------------------------------------------------------------- // void ServerInit(Server_t *server) { @@ -41,17 +41,13 @@ void ServerInit(Server_t *server) #define SEND_BUFFER_SIZE 80 * 24 #define RECEIVE_BUFFER_SIZE 80 -static void serverCommunicationInstance(void *serverCommunication) +static void serverCommunicationInstance(Server_t *args, int sockfd) { - ServerCommunication_t *args; char **argv = NULL; char receiveBuff[RECEIVE_BUFFER_SIZE]; char sendBuff[SEND_BUFFER_SIZE]; int tokenIndex; - args = (ServerCommunication_t*) serverCommunication; - printLog("Server communicator #%lu online\n", *args->id); - //Accept and incoming connection while(!args->pleaseStop) { @@ -60,7 +56,7 @@ static void serverCommunicationInstance(void *serverCommunication) printLog("Waiting for commands...\n"); // Read the message from client and copy it in buffer - read(args->sockfd, receiveBuff, sizeof(receiveBuff)); + read(sockfd, receiveBuff, sizeof(receiveBuff)); // Ignore null-sized request if (receiveBuff[0] == 0) @@ -90,7 +86,7 @@ static void serverCommunicationInstance(void *serverCommunication) } // and send that buffer to client - write(args->sockfd, sendBuff, sizeof(sendBuff)); + write(sockfd, sendBuff, sizeof(sendBuff)); } printLog("End of communications \n");