modesFreeClient() optimized to find new maxfd faster
This commit is contained in:
Malcolm Robb 2014-02-22 22:28:20 +00:00
parent f331887b7f
commit b9a1a3e650

View file

@ -146,14 +146,18 @@ void modesFreeClient(int fd) {
if (Modes.debug & MODES_DEBUG_NET) if (Modes.debug & MODES_DEBUG_NET)
printf("Closing client %d\n", fd); printf("Closing client %d\n", fd);
// If this was our maxfd, rescan the full clients array to check what's // If this was our maxfd, scan the clients array to find the new max.
// 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) { if (Modes.maxfd == fd) {
int j; int j;
Modes.maxfd = -1; Modes.maxfd = -1;
for (j = 0; j < MODES_NET_MAX_FD; j++) { for (j = fd-1; j >= 0; j--) {
if (Modes.clients[j]) Modes.maxfd = j; if (Modes.clients[j]) {
Modes.maxfd = j;
break;
}
} }
} }
} }