Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2012 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3959327 to your computer and use it in GitHub Desktop.
Save anonymous/3959327 to your computer and use it in GitHub Desktop.
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