Changeset 12541


Ignore:
Timestamp:
Jul 11, 2011, 8:48:06 PM (10 years ago)
Author:
jordan
Message:

(trunk libT) restore setrlimit(), although in an non-configurable mode.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r12514 r12541  
    3737#include <sys/types.h>
    3838#include <sys/stat.h>
    39 #ifdef HAVE_GETRLIMIT
    40  #include <sys/time.h> /* getrlimit */
    41  #include <sys/resource.h> /* getrlimit */
    42 #endif
     39#include <sys/time.h> /* getrlimit */
     40#include <sys/resource.h> /* getrlimit */
    4341#include <fcntl.h> /* O_LARGEFILE posix_fadvise */
    4442#include <unistd.h> /* lseek(), write(), ftruncate(), pread(), pwrite(), etc */
     
    525523    if( session->fdInfo == NULL )
    526524    {
    527         const int TR_MAX_OPEN_FILES = 32;
    528         struct tr_fdInfo * i = tr_new0( struct tr_fdInfo, 1 );
    529         fileset_construct( &i->fileset, TR_MAX_OPEN_FILES );
     525        struct rlimit limit;
     526        struct tr_fdInfo * i;
     527        const int FILE_CACHE_SIZE = 32;
     528
     529        /* Create the local file cache */
     530        i = tr_new0( struct tr_fdInfo, 1 );
     531        fileset_construct( &i->fileset, FILE_CACHE_SIZE );
    530532        session->fdInfo = i;
     533
     534        /* set the open-file limit to the largest safe size wrt FD_SETSIZE */
     535        if( !getrlimit( RLIMIT_NOFILE, &limit ) )
     536        {
     537            const int old_limit = (int) limit.rlim_cur;
     538            const int new_limit = MIN( limit.rlim_max, FD_SETSIZE );
     539            if( new_limit != old_limit )
     540            {
     541                limit.rlim_cur = new_limit;
     542                setrlimit( RLIMIT_NOFILE, &limit );
     543                getrlimit( RLIMIT_NOFILE, &limit );
     544                tr_inf( "Changed open file limit from %d to %d", old_limit, (int)limit.rlim_cur );
     545            }
     546        }
    531547    }
    532548}
Note: See TracChangeset for help on using the changeset viewer.