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;
struct {
pthread_t *id;
pthread_t id;
bool pleaseStop;
int socketfd;
int sockfd;
} typedef ServerCommunication_t;
/* -------------------------------------------------------------------------- */

View File

@ -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");