diff options
| author | cashmere <cashmere@autistici.org> | 2026-06-22 19:50:55 +0200 |
|---|---|---|
| committer | cashmere <cashmere@autistici.org> | 2026-06-22 19:50:55 +0200 |
| commit | 3f755f01deaa7e4dfe7fde2272056ba4a1c67eb5 (patch) | |
| tree | 0aeca9575c1e27e2fc4ddcad41635cc4906e0e72 | |
| parent | be7fba96face4ab219fb369d2284007807cc536b (diff) | |
| download | telnet-3f755f01deaa7e4dfe7fde2272056ba4a1c67eb5.tar.gz | |
src/main.c: accept multiple clients simultaneously
| -rw-r--r-- | src/main.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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]; |
