From f9d5e7a72c5deb915bb97449c49ce82dfa955522 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Sat, 16 Apr 2011 22:33:29 +0000 Subject: [PATCH] (trunk libT) #4165 "__FD_SETSIZE impact on open-file-limit and peer-limit-global" -- add safety guard in the file cache to prevent too many open files. --- libtransmission/fdlimit.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 810a7c814..0831a28af 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -746,8 +746,20 @@ tr_fdGetFileLimit( tr_session * session ) void tr_fdSetFileLimit( tr_session * session, int limit ) { + int max; + + /* This is a vaguely arbitrary number. + It takes announcer.c's MAX_CONCURRENT_TASKS into account, + plus extra positions for the listening sockets, + plus a few more just to be safe */ + const int buffer_slots = 128; + ensureSessionFdInfoExists( session ); + max = __FD_SETSIZE - session->fdInfo->socket_limit - buffer_slots; + if( limit > max ) + limit = max; + if( limit != tr_fdGetFileLimit( session ) ) { struct tr_fileset * set = get_fileset( session ); -- 2.40.0