Get client id before creating pipe: if client refused, no pipe created
This commit is contained in:
parent
d80cc79e8f
commit
39fde32fd6
1 changed files with 7 additions and 7 deletions
14
src/server.c
14
src/server.c
|
@ -93,13 +93,7 @@ int main(int argc, char *argv[]) {
|
|||
} 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 */
|
||||
/* Get client id to make sure we can handle him */
|
||||
if ((client_id = get_next_free_client_id()) == -1) {
|
||||
/* Client array is full, refuse connection */
|
||||
fprintf(stderr, "get_next_free_client_id: Client array must be full\n");
|
||||
|
@ -109,6 +103,12 @@ int main(int argc, char *argv[]) {
|
|||
continue;
|
||||
}
|
||||
|
||||
/* Create a pipe for message exchange between Dispatcher and ClientSender */
|
||||
if (pipe(message_pipe) != 0) {
|
||||
perror("pipe");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Start client threads */
|
||||
if (pthread_create(&clientsender, NULL, ClientSender, &clients[client_id]) != 0) {
|
||||
fprintf(stderr, "pthread_create: error for ClientSender\n");
|
||||
|
|
Loading…
Reference in a new issue