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.

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.