Ignore:
Timestamp:
Jul 4, 2009, 4:33:23 AM (13 years ago)
Author:
charles
Message:

(trunk libT) remove dead code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fdlimit.c

    r8777 r8780  
    6363#include "list.h"
    6464#include "net.h"
    65 #include "platform.h" /* tr_lock */
     65#include "platform.h" /* MAX_PATH_LENGTH, TR_PATH_DELIMITER */
    6666#include "utils.h"
    6767
     
    9696    int                   socketCount;
    9797    int                   socketLimit;
    98 
     98    int                   openFileLimit;
    9999    struct tr_openfile  * openFiles;
    100     int                   openFileLimit;
    101 
    102     tr_lock             * lock;
    103100};
    104101
     
    292289    char               * filename;
    293290    struct stat          sb;
    294     int                  alreadyExisted;
     291    tr_bool              alreadyExisted;
    295292
    296293    /* confirm the parent folder exists */
    297294    if( stat( folder, &sb ) || !S_ISDIR( sb.st_mode ) )
    298295    {
    299         tr_err( _( "Couldn't create \"%1$s\": parent folder \"%2$s\" does not exist" ), torrentFile, folder );
     296        tr_err( _( "Couldn't create \"%1$s\": \"%2$s\" is not a folder" ), torrentFile, folder );
    300297        return ENOENT;
    301298    }
     
    355352
    356353#ifdef HAVE_POSIX_FADVISE
     354    /* this doubles the OS level readahead buffer, which in practice
     355     * turns out to be a good thing, because many (most?) clients request
     356     * chunks of blocks in order */
    357357    posix_fadvise( file->fd, 0, 0, POSIX_FADV_SEQUENTIAL );
    358358#endif
     
    362362}
    363363
    364 static int
     364static TR_INLINE tr_bool
    365365fileIsOpen( const struct tr_openfile * o )
    366366{
     
    369369
    370370static void
    371 TrCloseFile( int i )
    372 {
    373     struct tr_openfile * o = &gFd->openFiles[i];
    374 
    375     assert( i >= 0 );
    376     assert( i < gFd->openFileLimit );
     371TrCloseFile( struct tr_openfile * o )
     372{
     373    assert( o != NULL );
    377374    assert( fileIsOpen( o ) );
    378375
    379376    tr_close_file( o->fd );
    380377    o->fd = -1;
    381     o->isCheckedOut = 0;
     378    o->isCheckedOut = FALSE;
    382379}
    383380
     
    404401    assert( folder && *folder );
    405402    assert( torrentFile && *torrentFile );
    406     assert( doWrite == 0 || doWrite == 1 );
     403    assert( tr_isBool( doWrite ) );
    407404
    408405    tr_snprintf( filename, sizeof( filename ), "%s%c%s", folder, TR_PATH_DELIMITER, torrentFile );
    409406    dbgmsg( "looking for file '%s', writable %c", filename, doWrite ? 'y' : 'n' );
    410 
    411     tr_lockLock( gFd->lock );
    412407
    413408    /* is it already open? */
     
    423418            continue;
    424419
    425         if( fileIsCheckedOut( o ) )
    426         {
    427             dbgmsg( "found it!  it's open, but checked out.  waiting..." );
    428             tr_lockUnlock( gFd->lock );
    429             tr_wait( 200 );
    430             tr_lockLock( gFd->lock );
    431             i = -1; /* reloop */
    432             continue;
    433         }
     420        assert( !fileIsCheckedOut( o ) );
    434421
    435422        if( doWrite && !o->isWritable )
    436423        {
    437424            dbgmsg( "found it!  it's open and available, but isn't writable. closing..." );
    438             TrCloseFile( i );
     425            TrCloseFile( o );
    439426            break;
    440427        }
     
    469456        }
    470457
    471         if( winner >= 0 )
    472         {
    473             if( fileIsOpen( &gFd->openFiles[winner] ) )
    474             {
    475                 dbgmsg( "closing file '%s', slot #%d",
    476                         gFd->openFiles[winner].filename,
    477                         winner );
    478                 TrCloseFile( winner );
    479             }
    480         }
    481         else
    482         {
    483             dbgmsg( "everything's full!  waiting for someone else to finish something" );
    484             tr_lockUnlock( gFd->lock );
    485             tr_wait( 200 );
    486             tr_lockLock( gFd->lock );
     458        assert( winner >= 0 );
     459       
     460        if( fileIsOpen( &gFd->openFiles[winner] ) )
     461        {
     462            dbgmsg( "closing file \"%s\"", gFd->openFiles[winner].filename );
     463            TrCloseFile( &gFd->openFiles[winner] );
    487464        }
    488465    }
     
    492469    if( !fileIsOpen( o ) )
    493470    {
    494         const int err = TrOpenFile( winner, folder, torrentFile, doWrite, preallocationMode, desiredFileSize );
     471        const int err = TrOpenFile( winner, folder, torrentFile, doWrite,
     472                                    preallocationMode, desiredFileSize );
    495473        if( err ) {
    496             tr_lockUnlock( gFd->lock );
    497474            errno = err;
    498475            return -1;
     
    509486    o->isCheckedOut = 1;
    510487    o->date = tr_date( );
    511     tr_lockUnlock( gFd->lock );
    512488    return o->fd;
    513489}
     
    516492tr_fdFileReturn( int fd )
    517493{
    518     int i;
    519 
    520     tr_lockLock( gFd->lock );
    521 
    522     for( i = 0; i < gFd->openFileLimit; ++i )
    523     {
    524         struct tr_openfile * o = &gFd->openFiles[i];
     494    struct tr_openfile * o;
     495    const struct tr_openfile * end;
     496
     497    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     498    {
    525499        if( o->fd != fd )
    526500            continue;
    527 
    528         dbgmsg( "releasing file '%s' in slot #%d", o->filename, i );
    529         o->isCheckedOut = 0;
    530 
     501        dbgmsg( "releasing file \"%s\"", o->filename );
     502        o->isCheckedOut = FALSE;
    531503        break;
    532504    }
    533 
    534     tr_lockUnlock( gFd->lock );
    535505}
    536506
     
    538508tr_fdFileClose( const char * filename )
    539509{
    540     int i;
    541     tr_lockLock( gFd->lock );
    542 
    543     for( i=0; i<gFd->openFileLimit; ++i )
    544     {
    545         struct tr_openfile * o = &gFd->openFiles[i];
     510    struct tr_openfile * o;
     511    const struct tr_openfile * end;
     512
     513    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     514    {
    546515        if( !fileIsOpen( o ) || strcmp( filename, o->filename ) )
    547516            continue;
    548 
    549         dbgmsg( "tr_fdFileClose closing '%s'", filename );
    550 
     517        dbgmsg( "tr_fdFileClose closing \"%s\"", filename );
    551518        assert( !o->isCheckedOut && "this is a test assertion... I *think* this is always true now" );
    552 
    553         TrCloseFile( i );
    554     }
    555 
    556     tr_lockUnlock( gFd->lock );
     519        TrCloseFile( o );
     520    }
    557521}
    558522
     
    560524tr_fdTorrentClose( int torrentId )
    561525{
    562     int i;
    563     tr_lockLock( gFd->lock );
    564 
    565     for( i=0; i<gFd->openFileLimit; ++i )
    566     {
    567         struct tr_openfile * o = &gFd->openFiles[i];
    568 
    569         assert( !o->isCheckedOut && "this is a test assertion... I *think* this is always true now" );
    570 
     526    struct tr_openfile * o;
     527    const struct tr_openfile * end;
     528
     529    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
    571530        if( fileIsOpen( o ) && o->torrentId == torrentId )
    572             TrCloseFile( i );
    573     }
    574 
    575     tr_lockUnlock( gFd->lock );
    576 }
    577 
     531            TrCloseFile( o );
     532}
    578533
    579534/***
     
    583538***/
    584539
    585 static int
     540static TR_INLINE int
    586541getSocketMax( struct tr_fd_s * gFd )
    587542{
     
    593548{
    594549    int s = -1;
    595 
    596     tr_lockLock( gFd->lock );
    597550
    598551    if( gFd->socketCount < getSocketMax( gFd ) )
     
    612565    assert( gFd->socketCount >= 0 );
    613566
    614     tr_lockUnlock( gFd->lock );
    615567    return s;
    616568}
     
    624576    unsigned int len;
    625577    struct sockaddr_storage sock;
    626     tr_lockLock( gFd->lock );
    627578
    628579    assert( addr );
     
    665616    }
    666617
    667     tr_lockUnlock( gFd->lock );
    668618    return s;
    669619}
    670620
    671 static void
    672 socketClose( int fd )
    673 {
    674     EVUTIL_CLOSESOCKET( fd );
    675 }
    676 
    677 void
    678 tr_fdSocketClose( int s )
    679 {
    680     tr_lockLock( gFd->lock );
    681 
    682     if( s >= 0 )
    683     {
    684         socketClose( s );
     621void
     622tr_fdSocketClose( int fd )
     623{
     624    if( fd >= 0 )
     625    {
     626        EVUTIL_CLOSESOCKET( fd );
    685627        --gFd->socketCount;
    686628    }
    687629
    688630    assert( gFd->socketCount >= 0 );
    689 
    690     tr_lockUnlock( gFd->lock );
    691631}
    692632
     
    706646    gFd->openFiles = tr_new0( struct tr_openfile, openFileLimit );
    707647    gFd->openFileLimit = openFileLimit;
    708     gFd->lock = tr_lockNew( );
    709648
    710649#ifdef HAVE_GETRLIMIT
     
    730669tr_fdClose( void )
    731670{
    732     int i = 0;
    733 
    734     for( i = 0; i < gFd->openFileLimit; ++i )
    735         if( fileIsOpen( &gFd->openFiles[i] ) )
    736             TrCloseFile( i );
    737 
    738     tr_lockFree( gFd->lock );
     671    struct tr_openfile * o;
     672    const struct tr_openfile * end;
     673
     674    for( o=gFd->openFiles, end=o+gFd->openFileLimit; o!=end; ++o )
     675        if( fileIsOpen( o ) )
     676            TrCloseFile( o );
    739677
    740678    tr_free( gFd->openFiles );
Note: See TracChangeset for help on using the changeset viewer.