From 3f755f01deaa7e4dfe7fde2272056ba4a1c67eb5 Mon Sep 17 00:00:00 2001 From: cashmere Date: Mon, 22 Jun 2026 19:50:55 +0200 Subject: src/main.c: accept multiple clients simultaneously --- src/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/main.c') 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]; -- cgit v1.3.1