Add message_pipe
This commit is contained in:
parent
b2c3523d05
commit
8fcbc243b3
2 changed files with 11 additions and 2 deletions
10
src/server.c
10
src/server.c
|
@ -22,6 +22,7 @@ struct client_details clients[MAX_CLIENTS];
|
|||
int main(void) {
|
||||
int serv_sockid, client_sockid;
|
||||
int nb_clients = 0;
|
||||
int message_pipe[2];
|
||||
struct sockaddr_in server_socket;
|
||||
struct sockaddr_in client_socket;
|
||||
pthread_t clientlistener, clientsender;
|
||||
|
@ -80,10 +81,17 @@ int main(void) {
|
|||
} else {
|
||||
printf("received connection from %s\n", ip4tostring(ntohl(client_socket.sin_addr.s_addr)));
|
||||
|
||||
/* Create a pipe for message exchange between Dispatcher and ClientSender */
|
||||
if (pipe(message_pipe) != 0) {
|
||||
perror("pipe");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Create client details */
|
||||
clients[nb_clients].id = 0; // TODO: finish
|
||||
clients[nb_clients].pipe = 0; // TODO: finish
|
||||
clients[nb_clients].sockid = client_sockid;
|
||||
clients[nb_clients].pipe[0] = message_pipe[0];
|
||||
clients[nb_clients].pipe[1] = message_pipe[1];
|
||||
nb_clients++;
|
||||
|
||||
if (pthread_create(&clientsender, NULL, ClientSender, &clients[nb_clients - 1]) != 0) {
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
/* Details for each client, used by Dispatcher and passed to client threads */
|
||||
struct client_details {
|
||||
int id, pipe, sockid;
|
||||
int id, sockid;
|
||||
int pipe[2];
|
||||
};
|
||||
|
||||
/* Thread, parses and handles messages */
|
||||
|
|
Loading…
Reference in a new issue