mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
(trunk libT) #2643 "Total UL/DL ratio reset when quitting abnormally" -- fixed.
This commit is contained in:
parent
9e9d7c82c7
commit
857e37bf77
3 changed files with 33 additions and 12 deletions
|
@ -482,6 +482,8 @@ onSaveTimer( int foo UNUSED, short bar UNUSED, void * vsession )
|
|||
while(( tor = tr_torrentNext( session, tor )))
|
||||
tr_torrentSave( tor );
|
||||
|
||||
tr_statsSaveDirty( session );
|
||||
|
||||
tr_timerAdd( session->saveTimer, SAVE_INTERVAL_SECS, 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ struct tr_stats_handle
|
|||
tr_session_stats single;
|
||||
tr_session_stats old;
|
||||
time_t startTime;
|
||||
tr_bool isDirty;
|
||||
};
|
||||
|
||||
static char*
|
||||
|
@ -117,24 +118,34 @@ tr_statsInit( tr_session * session )
|
|||
session->sessionStats = stats;
|
||||
}
|
||||
|
||||
void
|
||||
tr_statsClose( tr_session * session )
|
||||
{
|
||||
tr_session_stats cumulative = STATS_INIT;
|
||||
|
||||
tr_sessionGetCumulativeStats( session, &cumulative );
|
||||
saveCumulativeStats( session, &cumulative );
|
||||
|
||||
tr_free( session->sessionStats );
|
||||
session->sessionStats = NULL;
|
||||
}
|
||||
|
||||
static struct tr_stats_handle *
|
||||
getStats( const tr_session * session )
|
||||
{
|
||||
return session ? session->sessionStats : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
tr_statsSaveDirty( tr_session * session )
|
||||
{
|
||||
struct tr_stats_handle * h = getStats( session );
|
||||
if( ( h != NULL ) && h->isDirty )
|
||||
{
|
||||
tr_session_stats cumulative = STATS_INIT;
|
||||
tr_sessionGetCumulativeStats( session, &cumulative );
|
||||
saveCumulativeStats( session, &cumulative );
|
||||
h->isDirty = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tr_statsClose( tr_session * session )
|
||||
{
|
||||
tr_statsSaveDirty( session );
|
||||
|
||||
tr_free( session->sessionStats );
|
||||
session->sessionStats = NULL;
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -213,7 +224,10 @@ tr_statsAddUploaded( tr_session * session,
|
|||
struct tr_stats_handle * s;
|
||||
|
||||
if( ( s = getStats( session ) ) )
|
||||
{
|
||||
s->single.uploadedBytes += bytes;
|
||||
s->isDirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -223,7 +237,10 @@ tr_statsAddDownloaded( tr_session * session,
|
|||
struct tr_stats_handle * s;
|
||||
|
||||
if( ( s = getStats( session ) ) )
|
||||
{
|
||||
s->single.downloadedBytes += bytes;
|
||||
s->isDirty = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -21,6 +21,8 @@ void tr_statsInit ( tr_session * session );
|
|||
|
||||
void tr_statsClose ( tr_session * session );
|
||||
|
||||
void tr_statsSaveDirty ( tr_session * session );
|
||||
|
||||
void tr_statsAddUploaded ( tr_session * session,
|
||||
uint32_t bytes );
|
||||
|
||||
|
|
Loading…
Reference in a new issue