diff options
Diffstat (limited to 'lib/libostp')
-rw-r--r-- | lib/libostp/server.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/lib/libostp/server.c b/lib/libostp/server.c index 794eda0..0916d58 100644 --- a/lib/libostp/server.c +++ b/lib/libostp/server.c @@ -174,38 +174,6 @@ listener_poll(struct ostp_listener *lp) continue; } - /* Check if the servers socket has new connections */ - if (FD_ISSET(lp->serv_sockfd, &lp->client_fds)) { - caddr_len = sizeof(caddr); - client_sock = accept(lp->serv_sockfd, (struct sockaddr *)&caddr, - &caddr_len); - - if (client_sock < 0) { - perror("accept"); - continue; - } - - if (lp->client_count >= MAX_CLIENTS) { - printf("New connection rejected, max clients reached\n"); - close(client_sock); - continue; - } - - for (int i = 0; i < MAX_CLIENTS; ++i) { - c = &lp->clients[i]; - if (c->sockfd < 0) { - c->sockfd = client_sock; - c->authed = 0; - ++lp->client_count; - - ip = inet_ntoa(caddr.sin_addr); - printf("Incoming connection from %s\n", ip); - handle_client(&caddr, c, lp); - break; - } - } - } - /* Handle data from clients */ for (int i = 1; i < MAX_CLIENTS; ++i) { c = &lp->clients[i]; @@ -244,6 +212,38 @@ listener_poll(struct ostp_listener *lp) } } } + + /* Check if the servers socket has new connections */ + if (FD_ISSET(lp->serv_sockfd, &lp->client_fds)) { + caddr_len = sizeof(caddr); + client_sock = accept(lp->serv_sockfd, (struct sockaddr *)&caddr, + &caddr_len); + + if (client_sock < 0) { + perror("accept"); + continue; + } + + if (lp->client_count >= MAX_CLIENTS) { + printf("New connection rejected, max clients reached\n"); + close(client_sock); + continue; + } + + for (int i = 0; i < MAX_CLIENTS; ++i) { + c = &lp->clients[i]; + if (c->sockfd < 0) { + c->sockfd = client_sock; + c->authed = 0; + ++lp->client_count; + + ip = inet_ntoa(caddr.sin_addr); + printf("Incoming connection from %s\n", ip); + handle_client(&caddr, c, lp); + break; + } + } + } } close(client_sock); |