mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
Fix endgame bug that caused the last 2-3% to drag out forever in recent nightlies. Thanks SoftwareElves
This commit is contained in:
parent
ab191885b5
commit
3a73f6790e
2 changed files with 17 additions and 18 deletions
|
@ -613,10 +613,19 @@ writeEnd:
|
|||
&& peer->inRequestCount < peer->inRequestMax )
|
||||
{
|
||||
int i;
|
||||
int poolSize=0, endgame=0;
|
||||
int * pool = getPreferredPieces ( tor, peer, &poolSize, &endgame );
|
||||
int poolSize = 0;
|
||||
int * pool = getPreferredPieces ( tor, peer, &poolSize );
|
||||
const int endgame = !poolSize;
|
||||
|
||||
for( i=0; i<poolSize && peer->inRequestCount<peer->inRequestMax; )
|
||||
if( endgame ) /* endgame -- request everything we don't already have */
|
||||
{
|
||||
const tr_bitfield_t * blocks = tr_cpBlockBitfield( tor->completion );
|
||||
for( i=0; i<tor->blockCount && peer->inRequestCount<peer->inRequestMax; ++i ) {
|
||||
if( tr_bitfieldHas( blocks, i ) )
|
||||
sendRequest( tor, peer, i );
|
||||
}
|
||||
}
|
||||
else for( i=0; i<poolSize && peer->inRequestCount<peer->inRequestMax; )
|
||||
{
|
||||
int unused;
|
||||
const int piece = pool[i];
|
||||
|
@ -629,7 +638,7 @@ writeEnd:
|
|||
else ++i;
|
||||
}
|
||||
|
||||
free( pool );
|
||||
tr_free( pool );
|
||||
}
|
||||
|
||||
return TR_OK;
|
||||
|
|
|
@ -277,29 +277,19 @@ int comparePieces (const void * aIn, const void * bIn)
|
|||
|
||||
static int* getPreferredPieces( const tr_torrent_t * tor,
|
||||
const tr_peer_t * peer,
|
||||
int * pieceCount,
|
||||
int * endgame )
|
||||
int * pieceCount )
|
||||
{
|
||||
const tr_info_t * inf = &tor->info;
|
||||
|
||||
int i;
|
||||
int poolSize = 0;
|
||||
int * pool = malloc ( inf->pieceCount * sizeof(int) );
|
||||
|
||||
*endgame = 0;
|
||||
int * pool = tr_new( int, inf->pieceCount );
|
||||
|
||||
for( i=0; i<inf->pieceCount; ++i )
|
||||
if( isPieceInteresting( tor, peer, i ) )
|
||||
if( tr_cpMissingBlocksForPiece( tor->completion, i ) )
|
||||
pool[poolSize++] = i;
|
||||
|
||||
if( !poolSize ) {
|
||||
*endgame = 1;
|
||||
for( i=0; i<inf->pieceCount; ++i )
|
||||
if( isPieceInteresting( tor, peer, i ) )
|
||||
pool[poolSize++] = i;
|
||||
}
|
||||
|
||||
#if 0
|
||||
fprintf (stderr, "old pool: ");
|
||||
for (i=0; i<15 && i<poolSize; ++i ) fprintf (stderr, "%d, ", pool[i] );
|
||||
|
@ -309,7 +299,7 @@ fprintf (stderr, "\n");
|
|||
/* sort the rest from most interesting to least */
|
||||
if( poolSize > 1 )
|
||||
{
|
||||
PieceCompareData * p = malloc ( poolSize * sizeof(PieceCompareData) );
|
||||
PieceCompareData * p = tr_new( PieceCompareData, poolSize );
|
||||
|
||||
for( i=0; i<poolSize; ++i )
|
||||
{
|
||||
|
@ -331,7 +321,7 @@ fprintf (stderr, "\n");
|
|||
for( i=0; i<poolSize; ++i )
|
||||
pool[i] = p[i].piece;
|
||||
|
||||
free( p );
|
||||
tr_free( p );
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
Loading…
Reference in a new issue