From 0e4973936b8d0884f7ab4bc3a2c3e68aba371e46 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 31 Oct 2019 17:51:27 -0400 Subject: Iterator over pollfds in reverse This has two advantages: 1. When removing a client, we don't need to break the loop, since the swap-remove will replace the current pollfd with one we've already handled and we can safely move on to the next (previous) one. 2. If a new client connects for the same consumer (for example if the previous one is going to time out), it will start consuming messages for that consumer, rather than them being sent to the old client. --- bounce.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bounce.c') diff --git a/bounce.c b/bounce.c index cc6b34f..18b205e 100644 --- a/bounce.c +++ b/bounce.c @@ -232,7 +232,7 @@ int main(int argc, char *argv[]) { } if (nfds < 0) continue; - for (size_t i = 0; i < event.len; ++i) { + for (size_t i = event.len - 1; i < event.len; --i) { short revents = event.fds[i].revents; if (!revents) continue; @@ -268,7 +268,6 @@ int main(int argc, char *argv[]) { close(event.fds[i].fd); eventRemove(i); if (!--clients) serverFormat("AWAY :%s\r\n", away); - break; } } -- cgit 1.4.1