Ignore:
Timestamp:
Jan 10, 2008, 7:22:11 PM (14 years ago)
Author:
charles
Message:

mingw portability fixes: getrlimit/setrlimit in fdlimit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r4570 r4598  
    2323 *****************************************************************************/
    2424
     25#ifndef WIN32
     26#define HAVE_GETRLIMIT
     27#endif
     28
    2529#include <assert.h>
    2630#include <errno.h>
     
    3236#include <sys/types.h>
    3337#include <sys/stat.h>
     38#ifdef HAVE_GETRLIMIT
    3439#include <sys/time.h> /* getrlimit */
    3540#include <sys/resource.h> /* getrlimit */
     41#endif
    3642#include <unistd.h>
    3743#include <libgen.h> /* basename, dirname */
     
    452458{
    453459    int i;
    454     struct rlimit rlim;
    455460
    456461    assert( gFd == NULL );
     
    458463    gFd->lock = tr_lockNew( );
    459464
    460     getrlimit( RLIMIT_NOFILE, &rlim );
    461     rlim.rlim_cur = MIN( rlim.rlim_max, (rlim_t)(globalPeerLimit + NOFILE_BUFFER) );
    462     setrlimit( RLIMIT_NOFILE, &rlim );
    463     gFd->normalMax = rlim.rlim_cur - NOFILE_BUFFER;
     465#ifdef HAVE_GETRLIMIT
     466    {
     467        struct rlimit rlim;
     468        getrlimit( RLIMIT_NOFILE, &rlim );
     469        rlim.rlim_cur = MIN( rlim.rlim_max,
     470               (rlim_t)(globalPeerLimit + NOFILE_BUFFER) );
     471        setrlimit( RLIMIT_NOFILE, &rlim );
     472        gFd->normalMax = rlim.rlim_cur - NOFILE_BUFFER;
     473        tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", rlim.rlim_cur );
     474    }
     475#else
     476    gFd->normalMax = globalPeerLimit;
     477#endif
    464478    tr_dbg( "%d usable file descriptors", globalPeerLimit );
    465479
Note: See TracChangeset for help on using the changeset viewer.