commit - e824d03efa218415d3625d14d168dfc954b39ef6
commit + 1e3ef7ab4f803b6309fcddc11dc23ecc5f33be27
blob - 07fb904bc4bcb08f50ab7500cdacf488263b3e7e
blob + 8c40bd34cf507b21d8ca9a69230e0e5ecd6559f2
--- server.c
+++ server.c
void
loop(struct tls *ctx, int sock4, int sock6)
{
- int i;
+ int i, n;
struct client clients[MAX_USERS];
struct pollfd fds[MAX_USERS];
fds[1].fd = sock6;
for (;;) {
- if (poll(fds, MAX_USERS, INFTIM) == -1) {
+ if ((n = poll(fds, MAX_USERS, INFTIM)) == -1) {
if (errno == EINTR) {
- fprintf(stderr, "connected clients: %d\n",
+ fprintf(stderr, "connected clients: %d\n",
connected_clients);
- continue;
- }
- fatal("poll: %s", strerror(errno));
+ } else
+ fatal("poll: %s", strerror(errno));
}
- for (i = 0; i < MAX_USERS; i++) {
+ for (i = 0; i < MAX_USERS && n > 0; i++) {
if (fds[i].revents == 0)
continue;
fatal("bad fd %d: %s", fds[i].fd,
strerror(errno));
+ n--;
+
if (fds[i].revents & POLLHUP) {
/* fds[i] may be the fd of the stdin
* of a cgi script that has exited. */