mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
possible fix for the stats error reported in http://forum.transmissionbt.com/viewtopic.php?t=4843, but it's a strange bug.
This commit is contained in:
parent
6345b6ba11
commit
e44f2b7829
1 changed files with 22 additions and 19 deletions
|
@ -10,6 +10,8 @@
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "transmission.h"
|
#include "transmission.h"
|
||||||
#include "bencode.h"
|
#include "bencode.h"
|
||||||
#include "platform.h" /* tr_sessionGetConfigDir() */
|
#include "platform.h" /* tr_sessionGetConfigDir() */
|
||||||
|
@ -46,20 +48,16 @@ loadCumulativeStats( const tr_handle * handle, tr_session_stats * setme )
|
||||||
{
|
{
|
||||||
int64_t i;
|
int64_t i;
|
||||||
|
|
||||||
if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
|
|
||||||
setme->uploadedBytes = (uint64_t) i;
|
|
||||||
|
|
||||||
if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
|
if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
|
||||||
setme->downloadedBytes = (uint64_t) i;
|
setme->downloadedBytes = (uint64_t) i;
|
||||||
|
|
||||||
if( tr_bencDictFindInt( &top, "files-added", &i ) )
|
if( tr_bencDictFindInt( &top, "files-added", &i ) )
|
||||||
setme->filesAdded = (uint64_t) i;
|
setme->filesAdded = (uint64_t) i;
|
||||||
|
|
||||||
if( tr_bencDictFindInt( &top, "session-count", &i ) )
|
|
||||||
setme->sessionCount = (uint64_t) i;
|
|
||||||
|
|
||||||
if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
|
if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
|
||||||
setme->secondsActive = (uint64_t) i;
|
setme->secondsActive = (uint64_t) i;
|
||||||
|
if( tr_bencDictFindInt( &top, "session-count", &i ) )
|
||||||
|
setme->sessionCount = (uint64_t) i;
|
||||||
|
if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
|
||||||
|
setme->uploadedBytes = (uint64_t) i;
|
||||||
|
|
||||||
tr_bencFree( &top );
|
tr_bencFree( &top );
|
||||||
}
|
}
|
||||||
|
@ -72,11 +70,11 @@ saveCumulativeStats( const tr_handle * handle, const tr_session_stats * s )
|
||||||
tr_benc top;
|
tr_benc top;
|
||||||
|
|
||||||
tr_bencInitDict( &top, 5 );
|
tr_bencInitDict( &top, 5 );
|
||||||
tr_bencDictAddInt( &top, "uploaded-bytes", s->uploadedBytes );
|
|
||||||
tr_bencDictAddInt( &top, "downloaded-bytes", s->downloadedBytes );
|
tr_bencDictAddInt( &top, "downloaded-bytes", s->downloadedBytes );
|
||||||
tr_bencDictAddInt( &top, "files-added", s->filesAdded );
|
tr_bencDictAddInt( &top, "files-added", s->filesAdded );
|
||||||
tr_bencDictAddInt( &top, "session-count", s->sessionCount );
|
|
||||||
tr_bencDictAddInt( &top, "seconds-active", s->secondsActive );
|
tr_bencDictAddInt( &top, "seconds-active", s->secondsActive );
|
||||||
|
tr_bencDictAddInt( &top, "session-count", s->sessionCount );
|
||||||
|
tr_bencDictAddInt( &top, "uploaded-bytes", s->uploadedBytes );
|
||||||
|
|
||||||
getFilename( handle, filename, sizeof(filename) );
|
getFilename( handle, filename, sizeof(filename) );
|
||||||
tr_deepLog( __FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename );
|
tr_deepLog( __FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename );
|
||||||
|
@ -113,11 +111,7 @@ tr_statsClose( tr_handle * handle )
|
||||||
static struct tr_stats_handle *
|
static struct tr_stats_handle *
|
||||||
getStats( const tr_handle * handle )
|
getStats( const tr_handle * handle )
|
||||||
{
|
{
|
||||||
static struct tr_stats_handle nullObject;
|
return handle->sessionStats;
|
||||||
|
|
||||||
return handle && handle->sessionStats
|
|
||||||
? handle->sessionStats
|
|
||||||
: &nullObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -149,6 +143,7 @@ tr_sessionGetStats( const tr_handle * handle,
|
||||||
tr_session_stats * setme )
|
tr_session_stats * setme )
|
||||||
{
|
{
|
||||||
const struct tr_stats_handle * stats = getStats( handle );
|
const struct tr_stats_handle * stats = getStats( handle );
|
||||||
|
assert( stats != NULL );
|
||||||
*setme = stats->single;
|
*setme = stats->single;
|
||||||
setme->secondsActive = time( NULL ) - stats->startTime;
|
setme->secondsActive = time( NULL ) - stats->startTime;
|
||||||
updateRatio( setme );
|
updateRatio( setme );
|
||||||
|
@ -158,9 +153,11 @@ void
|
||||||
tr_sessionGetCumulativeStats( const tr_handle * handle,
|
tr_sessionGetCumulativeStats( const tr_handle * handle,
|
||||||
tr_session_stats * setme )
|
tr_session_stats * setme )
|
||||||
{
|
{
|
||||||
|
const struct tr_stats_handle * stats = getStats( handle );
|
||||||
|
assert( stats != NULL );
|
||||||
tr_session_stats current;
|
tr_session_stats current;
|
||||||
tr_sessionGetStats( handle, ¤t );
|
tr_sessionGetStats( handle, ¤t );
|
||||||
addStats( setme, &getStats(handle)->old, ¤t );
|
addStats( setme, &stats->old, ¤t );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -185,17 +182,23 @@ tr_sessionClearStats( tr_handle * handle )
|
||||||
void
|
void
|
||||||
tr_statsAddUploaded( tr_handle * handle, uint32_t bytes )
|
tr_statsAddUploaded( tr_handle * handle, uint32_t bytes )
|
||||||
{
|
{
|
||||||
getStats(handle)->single.uploadedBytes += bytes;
|
struct tr_stats_handle * s;
|
||||||
|
if(( s = getStats( handle )))
|
||||||
|
s->single.uploadedBytes += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_statsAddDownloaded( tr_handle * handle, uint32_t bytes )
|
tr_statsAddDownloaded( tr_handle * handle, uint32_t bytes )
|
||||||
{
|
{
|
||||||
getStats(handle)->single.downloadedBytes += bytes;
|
struct tr_stats_handle * s;
|
||||||
|
if(( s = getStats( handle )))
|
||||||
|
s->single.downloadedBytes += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tr_statsFileCreated( tr_handle * handle )
|
tr_statsFileCreated( tr_handle * handle )
|
||||||
{
|
{
|
||||||
getStats(handle)->single.filesAdded++;
|
struct tr_stats_handle * s;
|
||||||
|
if(( s = getStats( handle )))
|
||||||
|
s->single.filesAdded++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue