Check socket descriptor limit. #153

When calling select(), there's an upper limit for the socket descriptor
which is defined as FD_SETSIZE. When the socket descriptor is higher
than FD_SETSIZE, a call to select() will not work as expected, at least
for the proper sockets.

This patch adds an error message for this case.
This commit is contained in:
Stefan Schindler 2014-06-09 23:46:22 +02:00
parent 159176f5ba
commit 228038fa8a

View File

@ -75,6 +75,8 @@ void SocketSelector::add(Socket& socket)
{ {
SocketHandle handle = socket.getHandle(); SocketHandle handle = socket.getHandle();
if (handle != priv::SocketImpl::invalidSocket()) if (handle != priv::SocketImpl::invalidSocket())
{
if (handle < FD_SETSIZE)
{ {
FD_SET(handle, &m_impl->AllSockets); FD_SET(handle, &m_impl->AllSockets);
@ -82,6 +84,13 @@ void SocketSelector::add(Socket& socket)
if (size > m_impl->MaxSocket) if (size > m_impl->MaxSocket)
m_impl->MaxSocket = size; m_impl->MaxSocket = size;
} }
else
{
err() << "The socket can't be added to the selector because its "
<< "ID is too high. This is a limitation of your operating "
<< "system's FD_SETSIZE setting.";
}
}
} }