WIP: Rollback threaded server
This commit is contained in:
parent
8fe9e2125f
commit
ca7cb9294d
|
@ -125,9 +125,9 @@ struct {
|
|||
} typedef Server_t;
|
||||
|
||||
struct {
|
||||
pthread_t *id;
|
||||
pthread_t id;
|
||||
bool pleaseStop;
|
||||
int socketfd;
|
||||
int sockfd;
|
||||
} typedef ServerCommunication_t;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
|
12
src/server.c
12
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");
|
||||
|
|
Loading…
Reference in New Issue