Changeset 5979


Ignore:
Timestamp:
May 30, 2008, 5:22:26 PM (14 years ago)
Author:
charles
Message:

on shutdown, close the most active torrents first. That way if we can't get everyting closed in a reasonable amount of time, at least we get the ones that affect stats first.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r5975 r5979  
    398398}
    399399
     400/* close the biggest torrents first */
     401static int
     402compareTorrentByCur( 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
    400410static void
    401411tr_closeAllConnections( void * vh )
     
    403413    tr_handle * h = vh;
    404414    tr_torrent * tor;
     415    int i, n;
     416    tr_torrent ** torrents;
    405417
    406418    tr_sharedShuttingDown( h->shared );
     
    408420    tr_rpcClose( &h->rpcServer );
    409421
    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 );
    412434
    413435    tr_peerMgrFree( h->peerMgr );
  • trunk/libtransmission/utils.c

    r5976 r5979  
    355355}
    356356
     357int
     358tr_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
    357365/**
    358366***
  • trunk/libtransmission/utils.h

    r5860 r5979  
    218218int tr_compareUint16( uint16_t a, uint16_t b );
    219219int tr_compareUint32( uint32_t a, uint32_t b );
     220int tr_compareUint64( uint64_t a, uint64_t b );
    220221
    221222void tr_sha1_to_hex( char * out, const uint8_t * sha1 );
Note: See TracChangeset for help on using the changeset viewer.