summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-06-22 19:50:55 +0200
committercashmere <cashmere@autistici.org>2026-06-22 19:50:55 +0200
commit3f755f01deaa7e4dfe7fde2272056ba4a1c67eb5 (patch)
tree0aeca9575c1e27e2fc4ddcad41635cc4906e0e72 /src/main.c
parentbe7fba96face4ab219fb369d2284007807cc536b (diff)
downloadtelnet-3f755f01deaa7e4dfe7fde2272056ba4a1c67eb5.tar.gz
src/main.c: accept multiple clients simultaneously
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index a45a40c..a1825d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,10 +26,16 @@ int main() {
perror("could not listen");
return 1;
}
+ struct pollfd fds[256];
+ fds[0].fd = sfd; /* socket file descriptor */
+ fds[0].events = POLLIN; /* data to read */
+ nfds_t nfds = 1; /* non file descriptor. something with timeout */
while (1) {
- int conn = accept(sfd, NULL, NULL);
- if (conn == -1) {
- perror("could not accept connection");
+ /* we start the polling here */
+ int ready =
+ poll(fds, nfds, -1); /* poll to accept many conn simultaneously */
+ if (ready == -1) {
+ perror("could not run poll");
return 1;
}
char buf[1024];