Changeset 5979
- Timestamp:
- May 30, 2008, 5:22:26 PM (14 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/session.c
r5975 r5979 398 398 } 399 399 400 /* close the biggest torrents first */ 401 static int 402 compareTorrentByCur( const void * va, const void * vb ) 403 { 404 const tr_torrent * a = *(const tr_torrent**)va; 405 const tr_torrent * b = *(const tr_torrent**)vb; 406 return -tr_compareUint64( a->downloadedCur + a->uploadedCur, 407 b->downloadedCur + b->uploadedCur ); 408 } 409 400 410 static void 401 411 tr_closeAllConnections( void * vh ) … … 403 413 tr_handle * h = vh; 404 414 tr_torrent * tor; 415 int i, n; 416 tr_torrent ** torrents; 405 417 406 418 tr_sharedShuttingDown( h->shared ); … … 408 420 tr_rpcClose( &h->rpcServer ); 409 421 410 while(( tor = tr_torrentNext( h, NULL ))) 411 tr_torrentFree( tor ); 422 /* close the torrents. get the most active ones first so that 423 * if we can't get them all closed in a reasonable amount of time, 424 * at least we get the most important ones first. */ 425 tor = NULL; 426 n = h->torrentCount; 427 torrents = tr_new( tr_torrent*, h->torrentCount ); 428 for( i=0; i<n; ++i ) 429 torrents[i] = tr_torrentNext( h, tor ); 430 qsort( torrents, n, sizeof(tr_torrent*), compareTorrentByCur ); 431 for( i=0; i<n; ++i ) 432 tr_torrentFree( torrents[i] ); 433 tr_free( torrents ); 412 434 413 435 tr_peerMgrFree( h->peerMgr ); -
trunk/libtransmission/utils.c
r5976 r5979 355 355 } 356 356 357 int 358 tr_compareUint64( uint64_t a, uint64_t b ) 359 { 360 if( a < b ) return -1; 361 if( a > b ) return 1; 362 return 0; 363 } 364 357 365 /** 358 366 *** -
trunk/libtransmission/utils.h
r5860 r5979 218 218 int tr_compareUint16( uint16_t a, uint16_t b ); 219 219 int tr_compareUint32( uint32_t a, uint32_t b ); 220 int tr_compareUint64( uint64_t a, uint64_t b ); 220 221 221 222 void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
Note: See TracChangeset
for help on using the changeset viewer.