WIP: Rollback threaded server

This commit is contained in:
Adrien Bourmault 2021-07-08 18:35:14 +02:00
parent 8fe9e2125f
commit ca7cb9294d
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 6 additions and 10 deletions

View File

@ -125,9 +125,9 @@ struct {
} typedef Server_t; } typedef Server_t;
struct { struct {
pthread_t *id; pthread_t id;
bool pleaseStop; bool pleaseStop;
int socketfd; int sockfd;
} typedef ServerCommunication_t; } typedef ServerCommunication_t;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -31,7 +31,7 @@ static void *serverMain(void *server);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
// Server init function // // Server init function //
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
void ServerInit(Server_t *server) void ServerInit(Server_t *server)
{ {
@ -41,17 +41,13 @@ void ServerInit(Server_t *server)
#define SEND_BUFFER_SIZE 80 * 24 #define SEND_BUFFER_SIZE 80 * 24
#define RECEIVE_BUFFER_SIZE 80 #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 **argv = NULL;
char receiveBuff[RECEIVE_BUFFER_SIZE]; char receiveBuff[RECEIVE_BUFFER_SIZE];
char sendBuff[SEND_BUFFER_SIZE]; char sendBuff[SEND_BUFFER_SIZE];
int tokenIndex; int tokenIndex;
args = (ServerCommunication_t*) serverCommunication;
printLog("Server communicator #%lu online\n", *args->id);
//Accept and incoming connection //Accept and incoming connection
while(!args->pleaseStop) { while(!args->pleaseStop) {
@ -60,7 +56,7 @@ static void serverCommunicationInstance(void *serverCommunication)
printLog("Waiting for commands...\n"); printLog("Waiting for commands...\n");
// Read the message from client and copy it in buffer // 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 // Ignore null-sized request
if (receiveBuff[0] == 0) if (receiveBuff[0] == 0)
@ -90,7 +86,7 @@ static void serverCommunicationInstance(void *serverCommunication)
} }
// and send that buffer to client // and send that buffer to client
write(args->sockfd, sendBuff, sizeof(sendBuff)); write(sockfd, sendBuff, sizeof(sendBuff));
} }
printLog("End of communications \n"); printLog("End of communications \n");