1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +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:
Charles Kerr 2007-06-29 06:24:55 +00:00
parent ab191885b5
commit 3a73f6790e
2 changed files with 17 additions and 18 deletions

View file

@ -613,10 +613,19 @@ writeEnd:
&& peer->inRequestCount < peer->inRequestMax ) && peer->inRequestCount < peer->inRequestMax )
{ {
int i; int i;
int poolSize=0, endgame=0; int poolSize = 0;
int * pool = getPreferredPieces ( tor, peer, &poolSize, &endgame ); 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; int unused;
const int piece = pool[i]; const int piece = pool[i];
@ -629,7 +638,7 @@ writeEnd:
else ++i; else ++i;
} }
free( pool ); tr_free( pool );
} }
return TR_OK; return TR_OK;

View file

@ -277,29 +277,19 @@ int comparePieces (const void * aIn, const void * bIn)
static int* getPreferredPieces( const tr_torrent_t * tor, static int* getPreferredPieces( const tr_torrent_t * tor,
const tr_peer_t * peer, const tr_peer_t * peer,
int * pieceCount, int * pieceCount )
int * endgame )
{ {
const tr_info_t * inf = &tor->info; const tr_info_t * inf = &tor->info;
int i; int i;
int poolSize = 0; int poolSize = 0;
int * pool = malloc ( inf->pieceCount * sizeof(int) ); int * pool = tr_new( int, inf->pieceCount );
*endgame = 0;
for( i=0; i<inf->pieceCount; ++i ) for( i=0; i<inf->pieceCount; ++i )
if( isPieceInteresting( tor, peer, i ) ) if( isPieceInteresting( tor, peer, i ) )
if( tr_cpMissingBlocksForPiece( tor->completion, i ) ) if( tr_cpMissingBlocksForPiece( tor->completion, i ) )
pool[poolSize++] = 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 #if 0
fprintf (stderr, "old pool: "); fprintf (stderr, "old pool: ");
for (i=0; i<15 && i<poolSize; ++i ) fprintf (stderr, "%d, ", pool[i] ); 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 */ /* sort the rest from most interesting to least */
if( poolSize > 1 ) if( poolSize > 1 )
{ {
PieceCompareData * p = malloc ( poolSize * sizeof(PieceCompareData) ); PieceCompareData * p = tr_new( PieceCompareData, poolSize );
for( i=0; i<poolSize; ++i ) for( i=0; i<poolSize; ++i )
{ {
@ -331,7 +321,7 @@ fprintf (stderr, "\n");
for( i=0; i<poolSize; ++i ) for( i=0; i<poolSize; ++i )
pool[i] = p[i].piece; pool[i] = p[i].piece;
free( p ); tr_free( p );
} }
#if 0 #if 0