From f296d5a64d65ce53ae6e500a7c751c94d2cc15a4 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 16 May 2008 15:19:38 +0000 Subject: [PATCH] limits the number of connections depending to getrlimit(). Fixes #232 --- src/session_impl.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 778738a88..21ccd74c3 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -76,6 +76,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/enum_net.hpp" #include "libtorrent/config.hpp" +#ifndef TORRENT_WINDOWS +#include +#endif + #ifndef TORRENT_DISABLE_ENCRYPTION #include @@ -2142,7 +2146,19 @@ namespace aux { INVARIANT_CHECK; - if (limit <= 0) limit = (std::numeric_limits::max)(); + if (limit <= 0) + { + limit = (std::numeric_limits::max)(); +#ifndef TORRENT_WINDOWS + rlimit l; + if (getrlimit(RLIMIT_NOFILE, &l) == 0 + && l.rlim_cur != RLIM_INFINITY) + { + limit = l.rlim_cur - m_settings.file_pool_size; + if (limit < 5) limit = 5; + } +#endif + } m_max_connections = limit; }