(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.

This commit is contained in:
Jordan Lee 2011-04-16 22:33:29 +00:00
parent 64b2cd64fa
commit f9d5e7a72c
1 changed files with 12 additions and 0 deletions

View File

@ -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 );