diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index cfe7a6dfa..3f6140a88 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -558,6 +558,23 @@ tr_torrentStatCached( tr_torrent * tor ) : tr_torrentStat( tor ); } +tr_torrent_status +tr_torrentGetStatus( tr_torrent * tor ) +{ + tr_torrentRecheckCompleteness( tor ); + + if( tor->verifyState == TR_VERIFY_NOW ) + return TR_STATUS_CHECK; + if( tor->verifyState == TR_VERIFY_WAIT ) + return TR_STATUS_CHECK_WAIT; + if( !tor->isRunning ) + return TR_STATUS_STOPPED; + if( tor->cpStatus == TR_CP_INCOMPLETE ) + return TR_STATUS_DOWNLOAD; + + return TR_STATUS_SEED; +} + const tr_stat * tr_torrentStat( tr_torrent * tor ) { @@ -567,10 +584,9 @@ tr_torrentStat( tr_torrent * tor ) tr_torrentLock( tor ); tor->lastStatTime = time( NULL ); - tr_torrentRecheckCompleteness( tor ); s = &tor->stats; - + s->status = tr_torrentGetStatus( tor ); s->error = tor->error; memcpy( s->errorString, tor->errorString, sizeof( s->errorString ) ); @@ -595,17 +611,6 @@ tr_torrentStat( tr_torrent * tor ) s->percentDone = tr_cpPercentDone( tor->completion ); s->leftUntilDone = tr_cpLeftUntilDone( tor->completion ); - if( tor->verifyState == TR_VERIFY_NOW ) - s->status = TR_STATUS_CHECK; - else if( tor->verifyState == TR_VERIFY_WAIT ) - s->status = TR_STATUS_CHECK_WAIT; - else if( !tor->isRunning ) - s->status = TR_STATUS_STOPPED; - else if( tor->cpStatus == TR_CP_INCOMPLETE ) - s->status = TR_STATUS_DOWNLOAD; - else - s->status = TR_STATUS_SEED; - s->recheckProgress = 1.0 - (tr_torrentCountUncheckedPieces( tor ) / (double) tor->info.pieceCount); diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index c5b5b11f8..24953f6fc 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -347,17 +347,12 @@ tr_getGlobalPeerLimit( const tr_handle * handle UNUSED ) void tr_torrentRates( tr_handle * h, float * toClient, float * toPeer ) { - const tr_torrent * tor; tr_globalLock( h ); - *toClient = *toPeer = 0.0; - for( tor = h->torrentList; tor; tor = tor->next ) - { - float c, p; - tr_torrentGetRates( tor, &c, &p ); - *toClient += c; - *toPeer += p; - } + if( toClient ) + *toClient = tr_rcRate( h->download ); + if( toPeer ) + *toPeer = tr_rcRate( h->upload ); tr_globalUnlock( h ); } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 8c7bc7298..f0979a548 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -813,6 +813,8 @@ struct tr_tracker_stat time_t nextManualAnnounceTime; }; +tr_torrent_status tr_torrentGetStatus( tr_torrent * ); + struct tr_stat { tr_torrent_status status;