IO: Handle fd values too big for select()

If the number of sockets is too much for select(), we should at least
handle it with proper error messages and reject new sockets instead of
breaking the event loop.

Thanks to Alexander V. Chernikov for the patch.
This commit is contained in:
Ondrej Zajicek (work) 2015-11-03 11:08:57 +01:00
parent acb04cfdc5
commit 338f85ca77

View file

@ -1309,6 +1309,16 @@ sk_passive_connected(sock *s, int type)
return 0; return 0;
} }
if (fd >= FD_SETSIZE)
{
/* FIXME: Call err_hook instead ? */
log(L_ERR "SOCK: Incoming connection from %I%J (port %d) %s",
t->daddr, ipa_is_link_local(t->daddr) ? t->iface : NULL,
t->dport, "rejected due to FD_SETSIZE limit");
close(fd);
return 1;
}
sock *t = sk_new(s->pool); sock *t = sk_new(s->pool);
t->type = type; t->type = type;
t->fd = fd; t->fd = fd;
@ -1404,6 +1414,9 @@ sk_open(sock *s)
if (fd < 0) if (fd < 0)
ERR("socket"); ERR("socket");
if (fd >= FD_SETSIZE)
ERR2("FD_SETSIZE limit reached");
s->af = af; s->af = af;
s->fd = fd; s->fd = fd;