Changeset 2233


Ignore:
Timestamp:
Jun 29, 2007, 6:24:55 AM (15 years ago)
Author:
charles
Message:

Fix endgame bug that caused the last 2-3% to drag out forever in recent nightlies. Thanks SoftwareElves?

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer.c

    r2232 r2233  
    614614    {
    615615        int i;
    616         int poolSize=0, endgame=0;
    617         int * pool = getPreferredPieces ( tor, peer, &poolSize, &endgame );
    618 
    619         for( i=0; i<poolSize && peer->inRequestCount<peer->inRequestMax;  )
     616        int poolSize = 0;
     617        int * pool = getPreferredPieces ( tor, peer, &poolSize );
     618        const int endgame = !poolSize;
     619
     620        if( endgame ) /* endgame -- request everything we don't already have */
     621        {
     622            const tr_bitfield_t * blocks = tr_cpBlockBitfield( tor->completion );
     623            for( i=0; i<tor->blockCount && peer->inRequestCount<peer->inRequestMax; ++i ) {
     624                if( tr_bitfieldHas( blocks, i ) )
     625                    sendRequest( tor, peer, i );
     626            }
     627        }
     628        else for( i=0; i<poolSize && peer->inRequestCount<peer->inRequestMax;  )
    620629        {
    621630            int unused;
     
    630639        }
    631640
    632         free( pool );
     641        tr_free( pool );
    633642    }
    634643
  • trunk/libtransmission/peerutils.h

    r2149 r2233  
    278278static int* getPreferredPieces( const tr_torrent_t  * tor,
    279279                                const tr_peer_t     * peer,
    280                                 int                 * pieceCount,
    281                                 int                 * endgame )
     280                                int                 * pieceCount )
    282281{
    283282    const tr_info_t * inf = &tor->info;
     
    285284    int i;
    286285    int poolSize = 0;
    287     int * pool = malloc ( inf->pieceCount * sizeof(int) );
    288 
    289     *endgame = 0;
     286    int * pool = tr_new( int, inf->pieceCount );
    290287
    291288    for( i=0; i<inf->pieceCount; ++i )
     
    293290            if( tr_cpMissingBlocksForPiece( tor->completion, i ) )
    294291                pool[poolSize++] = i;
    295 
    296     if( !poolSize ) {
    297         *endgame = 1;
    298         for( i=0; i<inf->pieceCount; ++i )
    299             if( isPieceInteresting( tor, peer, i ) )
    300                 pool[poolSize++] = i;
    301     }
    302292
    303293#if 0
     
    310300    if( poolSize > 1 )
    311301    {
    312         PieceCompareData * p = malloc ( poolSize * sizeof(PieceCompareData) );
     302        PieceCompareData * p = tr_new( PieceCompareData, poolSize );
    313303
    314304        for( i=0; i<poolSize; ++i )
     
    332322            pool[i] = p[i].piece;
    333323
    334         free( p );
     324        tr_free( p );
    335325    }
    336326
Note: See TracChangeset for help on using the changeset viewer.