From f84c0aa2cdfcf8d21cb0c5840f6886e2b3a1a6c4 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 30 Oct 2014 14:51:53 +1100 Subject: [PATCH] Make number of clients we can connect to unlimited --- src/connector.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/connector.c b/src/connector.c index 2acaf19c..35289338 100644 --- a/src/connector.c +++ b/src/connector.c @@ -293,12 +293,13 @@ void *receiver(void *arg) { conn_instance_t *ci = (conn_instance_t *)arg; client_instance_t *client, *tmp; - struct pollfd fds[65536]; - int ret, nfds, i; + int ret, nfds, i, maxfds = 1; + struct pollfd *fds; bool update; rename_proc("creceiver"); + fds = ckalloc(sizeof(struct pollfd)); /* First fd is reserved for the accepting socket */ fds[0].fd = ci->serverfd; fds[0].events = POLLIN; @@ -314,6 +315,14 @@ rebuild_fds: client->id); continue; } + if (nfds >= maxfds) { + maxfds = nfds + 1; + fds = realloc(fds, sizeof(struct pollfd) * maxfds); + if (unlikely(!fds)) { + LOGEMERG("FATAL: Failed to realloc fds in receiver!"); + goto out; + } + } fds[nfds].fd = client->fd; fds[nfds].events = POLLIN; fds[nfds].revents = 0; @@ -372,6 +381,7 @@ repoll: goto rebuild_fds; goto repoll; out: + free(fds); return NULL; }