summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-10-31 17:51:27 -0400
committerJune McEnroe <june@causal.agency>2019-10-31 17:51:27 -0400
commit0e4973936b8d0884f7ab4bc3a2c3e68aba371e46 (patch)
tree68fba322c3194f73ef11d548a508f5a06c5cd81e
parentClear passwords from memory with memset_s (diff)
downloadpounce-0e4973936b8d0884f7ab4bc3a2c3e68aba371e46.tar.gz
pounce-0e4973936b8d0884f7ab4bc3a2c3e68aba371e46.zip
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.
Diffstat (limited to '')
-rw-r--r--bounce.c3
1 files changed, 1 insertions, 2 deletions
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;
 			}
 		}
 
ansi&id=3c2d8233b880cb22e2330a877f7d9ee1a9a8a5fa&follow=1'>Madvise RANDOM and NOSYNCJune McEnroe 2017-07-31Fix removing clients from clientCastJune McEnroe 2017-07-31Build with debug infoJune McEnroe 2017-07-31Don't dump tiles in coreJune McEnroe 2017-07-31Use designated initializers for messagesJune McEnroe I did not realize this syntax was so powerful. 2017-07-31Show other clients' cursorsJune McEnroe Also unfuck removing on send failure. 2017-07-31Perform enter as two moves rather than a loopJune McEnroe 2017-07-31Track tile access countsJune McEnroe 2017-07-31Adjust move speed in clientJune McEnroe 2017-07-31Handle large movesJune McEnroe 2017-07-30Optimize builds for chrootJune McEnroe 2017-07-30Persist bright across color changesJune McEnroe 2017-07-30Add index.htmlJune McEnroe 2017-07-30Add snapshot.shJune McEnroe 2017-07-30Fix termcap patch for background colorsJune McEnroe 2017-07-30Update helpJune McEnroe 2017-07-30Fix help to track colorJune McEnroe 2017-07-30Support background colorsJune McEnroe 2017-07-30Track color only client-sideJune McEnroe 2017-07-30Add ostensible support for background colorsJune McEnroe 2017-07-30Add tile create and access timestampsJune McEnroe 2017-07-30Assert stable struct Tile field offsetsJune McEnroe 2017-07-30Add chroot.shJune McEnroe 2017-07-30Add ` commandJune McEnroe 2017-07-30Add sshd_configJune McEnroe 2017-07-30Add termcap patchJune McEnroe