WIP: Rollback threaded server
This commit is contained in:
parent
8fe9e2125f
commit
ca7cb9294d
|
@ -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;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
10
src/server.c
10
src/server.c
|
@ -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");
|
||||||
|
|
Loading…
Reference in New Issue