mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(1) make tr_torrentRates() faster.
(2) new function: tr_torrentGetStatus() for when you need the status but not the overhead of tr_stat
This commit is contained in:
parent
2399846dd8
commit
eb24ad760d
3 changed files with 24 additions and 22 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue