Ignore:
Timestamp:
Nov 1, 2007, 1:47:32 PM (15 years ago)
Author:
charles
Message:

finish cleaning up the code that was churned during the "corruption" fix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r3666 r3674  
    9090enum
    9191{
     92    TR_MAX_SOCKETS = 1024,
     93
    9294    TR_MAX_OPEN_FILES = 16, /* real files, not sockets */
    9395
     
    126128{
    127129    struct tr_openfile * file = &gFd->open[i];
    128     char * dir;
    129130    int flags;
    130131
     
    132133
    133134    /* create subfolders, if any */
    134     dir = dirname( tr_strdup( filename ) );
    135     if( write && tr_mkdirp( dir, 0700 ) ) {
    136         free( dir );
    137         return tr_ioErrorFromErrno( );
     135    if( write ) {
     136        char * dir = dirname( tr_strdup( filename ) );
     137        const int val = tr_mkdirp( dir, 0700 );
     138        tr_free( dir );
     139        if( val )
     140            return tr_ioErrorFromErrno( );
    138141    }
    139142
     
    145148    errno = 0;
    146149    file->fd = open( filename, flags, 0600 );
    147     free( dir );
    148150    if( file->fd < 0 ) {
    149151        if( errno ) {
     
    233235    for( ;; )
    234236    {
    235         uint64_t date = tr_date() + 1;
     237        uint64_t date = tr_date( ) + 1;
    236238        winner = -1;
    237239
     
    281283    dbgmsg( "checking out '%s' in slot %d", filename, winner );
    282284    o->isCheckedOut = 1;
    283     o->date = tr_date();
     285    o->date = tr_date( );
    284286    tr_lockUnlock( gFd->lock );
    285287    return o->fd;
     
    296298        if( o->fd == file ) {
    297299            dbgmsg( "releasing file '%s' in slot #%d", o->filename, i );
    298             if( o->isWritable )
    299                 fsync( o->fd ); /* fflush */
     300            fsync( o->fd );
    300301            o->isCheckedOut = 0;
    301302            break;
     
    329330
    330331int
    331 tr_fdSocketCreate( int type, int priority )
     332tr_fdSocketCreate( int type, int isReserved )
    332333{
    333334    int s = -1;
    334335    tr_lockLock( gFd->lock );
    335336
    336     if( priority && gFd->reserved >= TR_RESERVED_FDS )
    337         priority = FALSE;
    338 
    339     if( priority || ( gFd->normal < gFd->normalMax ) )
     337    if( isReserved && gFd->reserved >= TR_RESERVED_FDS )
     338        isReserved = FALSE;
     339
     340    if( isReserved || ( gFd->normal < gFd->normalMax ) )
    340341        if( ( s = socket( AF_INET, type, 0 ) ) < 0 )
    341342            tr_err( "Couldn't create socket (%s)", strerror( sockerrno ) );
     
    343344    if( s > -1 )
    344345    {
    345         setSocketPriority( s, priority );
    346 
    347         if( priority )
     346        setSocketPriority( s, isReserved );
     347
     348        if( isReserved )
    348349            ++gFd->reserved;
    349350        else
     
    376377    if( s > -1 )
    377378    {
    378         setSocketPriority( s, 0 );
     379        setSocketPriority( s, FALSE );
    379380        *addr = sock.sin_addr;
    380381        *port = sock.sin_port;
     
    424425tr_fdInit( void )
    425426{
    426     int i, j, s[4096];
     427    int i, j, s[TR_MAX_SOCKETS];
    427428
    428429    assert( gFd == NULL );
     
    433434
    434435    /* count the max number of sockets we can use */
    435     for( i=0; i<4096; ++i )
     436    for( i=0; i<TR_MAX_SOCKETS; ++i )
    436437        if( ( s[i] = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 )
    437438            break;
Note: See TracChangeset for help on using the changeset viewer.