Instantly share code, notes, and snippets.

anonymous /sequential-download.patch
Created Oct 26, 2012

Embed
What would you like to do?
Transmission sequential download patch
Index: libtransmission/peer-mgr.c
===================================================================
--- libtransmission/peer-mgr.c (revision 13594)
+++ libtransmission/peer-mgr.c (working copy)
@@ -982,6 +982,27 @@
}
static int
+comparePieceForSequential( const void * va, const void * vb )
+{
+ const struct weighted_piece * a = va;
+ const struct weighted_piece * b = vb;
+ int ia, ib;
+ const tr_torrent * tor = weightTorrent;
+
+ /* primary key: higher priorities go first */
+ ia = tor->info.pieces[a->index].priority;
+ ib = tor->info.pieces[b->index].priority;
+ if( ia > ib ) return -1;
+ if( ia < ib ) return 1;
+
+ /* secondary key: sequential */
+ if( a->index < b->index ) return -1;
+ if( a->index > b->index ) return 1;
+
+ return 0;
+}
+
+static int
comparePieceByIndex( const void * va, const void * vb )
{
const struct weighted_piece * a = va;
@@ -1001,7 +1022,7 @@
if( state == PIECES_SORTED_BY_WEIGHT )
{
setComparePieceByWeightTorrent( t );
- qsort( t->pieces, t->pieceCount, sizeof( struct weighted_piece ), comparePieceByWeight );
+ qsort( t->pieces, t->pieceCount, sizeof( struct weighted_piece ), comparePieceForSequential );
}
else
qsort( t->pieces, t->pieceCount, sizeof( struct weighted_piece ), comparePieceByIndex );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment