Changeset 10328


Ignore:
Timestamp:
Mar 7, 2010, 10:36:20 PM (12 years ago)
Author:
charles
Message:

(1.9x libT) this test shouldn't be enabled in the stable builds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.9x/libtransmission/peer-mgr.c

    r10302 r10328  
    729729}
    730730
     731static int
     732comparePieceByIndex( const void * va, const void * vb )
     733{
     734    const struct weighted_piece * a = va;
     735    const struct weighted_piece * b = vb;
     736    if( a->index < b->index ) return -1;
     737    if( a->index > b->index ) return 1;
     738    return 0;
     739}
     740
     741static void
     742pieceListSort( Torrent * t, int mode )
     743{
     744    int(*compar)(const void *, const void *);
     745
     746    assert( mode==PIECES_SORTED_BY_INDEX
     747         || mode==PIECES_SORTED_BY_WEIGHT );
     748
     749    switch( mode ) {
     750        case PIECES_SORTED_BY_WEIGHT: compar = comparePieceByWeight; break;
     751        case PIECES_SORTED_BY_INDEX: compar = comparePieceByIndex; break;
     752        default: assert( 0 && "unhandled" );  break;
     753    }
     754
     755    weightTorrent = t->tor;
     756    qsort( t->pieces, t->pieceCount,
     757           sizeof( struct weighted_piece ), compar );
     758}
     759
     760static tr_bool
     761isInEndgame( Torrent * t )
     762{
     763    tr_bool endgame = FALSE;
     764
     765    if( ( t->pieces != NULL ) && ( t->pieceCount > 0 ) )
     766    {
     767        const struct weighted_piece * p = t->pieces;
     768        const int pending = p->requestCount;
     769        const int missing = tr_cpMissingBlocksInPiece( &t->tor->completion, p->index );
     770        endgame = pending >= missing;
     771    }
     772
     773    /*if( endgame ) fprintf( stderr, "ENDGAME reached\n" );*/
     774    return endgame;
     775}
     776
    731777/**
    732778 * This function is useful for sanity checking,
     
    734780 * let's leave it disabled but add an easy hook to compile it back in
    735781 */
    736 #if 1
     782#if 0
    737783static void
    738784assertWeightedPiecesAreSorted( Torrent * t )
    739785{
    740     int i;
    741     weightTorrent = t->tor;
    742     for( i=0; i<t->pieceCount-1; ++i )
    743         assert( comparePieceByWeight( &t->pieces[i], &t->pieces[i+1] ) <= 0 );
     786    if( !isInEndgame( t ) )
     787    {
     788        int i;
     789        weightTorrent = t->tor;
     790        for( i=0; i<t->pieceCount-1; ++i )
     791            assert( comparePieceByWeight( &t->pieces[i], &t->pieces[i+1] ) <= 0 );
     792    }
    744793}
    745794#else
    746795#define assertWeightedPiecesAreSorted(t)
    747796#endif
    748 
    749 static int
    750 comparePieceByIndex( const void * va, const void * vb )
    751 {
    752     const struct weighted_piece * a = va;
    753     const struct weighted_piece * b = vb;
    754     if( a->index < b->index ) return -1;
    755     if( a->index > b->index ) return 1;
    756     return 0;
    757 }
    758 
    759 static void
    760 pieceListSort( Torrent * t, int mode )
    761 {
    762     int(*compar)(const void *, const void *);
    763 
    764     assert( mode==PIECES_SORTED_BY_INDEX
    765          || mode==PIECES_SORTED_BY_WEIGHT );
    766 
    767     switch( mode ) {
    768         case PIECES_SORTED_BY_WEIGHT: compar = comparePieceByWeight; break;
    769         case PIECES_SORTED_BY_INDEX: compar = comparePieceByIndex; break;
    770         default: assert( 0 && "unhandled" );  break;
    771     }
    772 
    773     weightTorrent = t->tor;
    774     qsort( t->pieces, t->pieceCount,
    775            sizeof( struct weighted_piece ), compar );
    776 }
    777 
    778 static tr_bool
    779 isInEndgame( Torrent * t )
    780 {
    781     tr_bool endgame = FALSE;
    782 
    783     if( ( t->pieces != NULL ) && ( t->pieceCount > 0 ) )
    784     {
    785         const struct weighted_piece * p = t->pieces;
    786         const int pending = p->requestCount;
    787         const int missing = tr_cpMissingBlocksInPiece( &t->tor->completion, p->index );
    788         endgame = pending >= missing;
    789     }
    790 
    791     /*if( endgame ) fprintf( stderr, "ENDGAME reached\n" );*/
    792     return endgame;
    793 }
    794797
    795798static struct weighted_piece *
Note: See TracChangeset for help on using the changeset viewer.