Ignore:
Timestamp:
Oct 14, 2008, 8:44:41 PM (13 years ago)
Author:
charles
Message:

(libT) dead code removal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r6899 r6906  
    5353#include "utils.h"
    5454
    55 #if SIZEOF_VOIDP == 8
    56  #define TR_UINT_TO_PTR( i ) (void*)( (uint64_t)i )
    57 #else
    58  #define TR_UINT_TO_PTR( i ) ( (void*)( (uint32_t)i ) )
    59 #endif
    60 
    6155#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ )
    6256
     
    8579struct tr_fd_s
    8680{
    87     int                   reserved;
    88     int                   normal;
    89     int                   normalMax;
     81    int                   socketCount;
     82    int                   socketMax;
    9083    tr_lock *             lock;
    9184    struct tr_openfile    open[TR_MAX_OPEN_FILES];
     
    369362***/
    370363
    371 static tr_list * reservedSockets = NULL;
    372 
    373 static void
    374 setSocketPriority( int fd,
    375                    int isReserved )
    376 {
    377     if( isReserved )
    378         tr_list_append( &reservedSockets, TR_UINT_TO_PTR( fd ) );
    379 }
    380 
    381 static int
    382 socketWasReserved( int fd )
    383 {
    384     return tr_list_remove_data( &reservedSockets,
    385                                TR_UINT_TO_PTR( fd ) ) != NULL;
    386 }
    387 
    388364static int
    389365getSocketMax( struct tr_fd_s * gFd )
    390366{
    391     return gFd->normalMax;
     367    return gFd->socketMax;
    392368}
    393369
    394370int
    395 tr_fdSocketCreate( int type,
    396                    int isReserved )
     371tr_fdSocketCreate( int type )
    397372{
    398373    int s = -1;
     
    400375    tr_lockLock( gFd->lock );
    401376
    402     if( isReserved || ( gFd->normal < getSocketMax( gFd ) ) )
     377    if( gFd->socketCount < getSocketMax( gFd ) )
    403378        if( ( s = socket( AF_INET, type, 0 ) ) < 0 )
    404379            tr_err( _( "Couldn't create socket: %s" ),
     
    406381
    407382    if( s > -1 )
    408     {
    409         setSocketPriority( s, isReserved );
    410 
    411         if( isReserved )
    412             ++gFd->reserved;
    413         else
    414             ++gFd->normal;
    415     }
    416 
    417     assert( gFd->reserved >= 0 );
    418     assert( gFd->normal >= 0 );
     383        ++gFd->socketCount;
     384
     385    assert( gFd->socketCount >= 0 );
    419386
    420387    tr_lockUnlock( gFd->lock );
     
    435402
    436403    tr_lockLock( gFd->lock );
    437     if( gFd->normal < getSocketMax( gFd ) )
     404    if( gFd->socketCount < getSocketMax( gFd ) )
    438405    {
    439406        len = sizeof( sock );
     
    442409    if( s > -1 )
    443410    {
    444         setSocketPriority( s, FALSE );
    445411        *addr = sock.sin_addr;
    446412        *port = sock.sin_port;
    447         gFd->normal++;
     413        ++gFd->socketCount;
    448414    }
    449415    tr_lockUnlock( gFd->lock );
     
    470436    {
    471437        socketClose( s );
    472         if( socketWasReserved( s ) )
    473             --gFd->reserved;
    474         else
    475             --gFd->normal;
    476     }
    477 
    478     assert( gFd->reserved >= 0 );
    479     assert( gFd->normal >= 0 );
     438        --gFd->socketCount;
     439    }
     440
     441    assert( gFd->socketCount >= 0 );
    480442
    481443    tr_lockUnlock( gFd->lock );
     
    504466                            (rlim_t)( globalPeerLimit + NOFILE_BUFFER ) );
    505467        setrlimit( RLIMIT_NOFILE, &rlim );
    506         gFd->normalMax = rlim.rlim_cur - NOFILE_BUFFER;
     468        gFd->socketMax = rlim.rlim_cur - NOFILE_BUFFER;
    507469        tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur );
    508470    }
    509471#else
    510     gFd->normalMax = globalPeerLimit;
     472    gFd->socketMax = globalPeerLimit;
    511473#endif
    512474    tr_dbg( "%d usable file descriptors", globalPeerLimit );
     
    527489    tr_lockFree( gFd->lock );
    528490
    529     tr_list_free( &reservedSockets, NULL );
    530491    tr_free( gFd );
    531492}
     
    535496{
    536497    assert( gFd != NULL && "tr_fdInit() must be called first!" );
    537     gFd->normalMax = n;
     498    gFd->socketMax = n;
    538499}
    539500
     
    541502tr_fdGetPeerLimit( void )
    542503{
    543     return gFd ? gFd->normalMax : -1;
    544 }
    545 
     504    return gFd ? gFd->socketMax : -1;
     505}
     506
Note: See TracChangeset for help on using the changeset viewer.