From 228038fa8a9cf0c90e1067dcc12c177bb77c8bab Mon Sep 17 00:00:00 2001 From: Stefan Schindler Date: Mon, 9 Jun 2014 23:46:22 +0200 Subject: [PATCH] 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. --- src/SFML/Network/SocketSelector.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index fa671557c..51896544b 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -76,11 +76,20 @@ void SocketSelector::add(Socket& socket) SocketHandle handle = socket.getHandle(); if (handle != priv::SocketImpl::invalidSocket()) { - FD_SET(handle, &m_impl->AllSockets); + if (handle < FD_SETSIZE) + { + FD_SET(handle, &m_impl->AllSockets); - int size = static_cast(handle); - if (size > m_impl->MaxSocket) - m_impl->MaxSocket = size; + int size = static_cast(handle); + if (size > m_impl->MaxSocket) + 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."; + } } }