From 7d03c180a07f917178f47fe7fcaa5ba098bd39b9 Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 14 Dec 2013 22:42:54 +0100 Subject: [PATCH] modesFreeClient() optimized to find new maxfd faster. --- dump1090.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dump1090.c b/dump1090.c index ad179d3..9a5fbc6 100644 --- a/dump1090.c +++ b/dump1090.c @@ -1975,14 +1975,18 @@ void modesFreeClient(int fd) { if (Modes.debug & MODES_DEBUG_NET) printf("Closing client %d\n", fd); - /* If this was our maxfd, rescan the full clients array to check what's - * the new max. */ + /* If this was our maxfd, scan the clients array to find the new max. + * Note that we are sure there is no active fd greater than the closed + * fd, so we scan from fd-1 to 0. */ if (Modes.maxfd == fd) { int j; Modes.maxfd = -1; - for (j = 0; j < MODES_NET_MAX_FD; j++) { - if (Modes.clients[j]) Modes.maxfd = j; + for (j = fd-1; j >= 0; j--) { + if (Modes.clients[j]) { + Modes.maxfd = j; + break; + } } } }