Changeset 5916


Ignore:
Timestamp:
May 23, 2008, 6:30:49 PM (14 years ago)
Author:
charles
Message:

possible fix for the stats error reported in http://forum.transmissionbt.com/viewtopic.php?t=4843, but it's a strange bug.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/stats.c

    r5908 r5916  
    1111 */
    1212
     13#include <assert.h>
     14
    1315#include "transmission.h"
    1416#include "bencode.h"
     
    4749        int64_t i;
    4850
     51        if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
     52            setme->downloadedBytes = (uint64_t) i;
     53        if( tr_bencDictFindInt( &top, "files-added", &i ) )
     54            setme->filesAdded = (uint64_t) i;
     55        if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
     56            setme->secondsActive = (uint64_t) i;
     57        if( tr_bencDictFindInt( &top, "session-count", &i ) )
     58            setme->sessionCount = (uint64_t) i;
    4959        if( tr_bencDictFindInt( &top, "uploaded-bytes", &i ) )
    5060            setme->uploadedBytes = (uint64_t) i;
    5161
    52         if( tr_bencDictFindInt( &top, "downloaded-bytes", &i ) )
    53             setme->downloadedBytes = (uint64_t) i;
    54 
    55         if( tr_bencDictFindInt( &top, "files-added", &i ) )
    56             setme->filesAdded = (uint64_t) i;
    57 
    58         if( tr_bencDictFindInt( &top, "session-count", &i ) )
    59             setme->sessionCount = (uint64_t) i;
    60 
    61         if( tr_bencDictFindInt( &top, "seconds-active", &i ) )
    62             setme->secondsActive = (uint64_t) i;
    63 
    6462        tr_bencFree( &top );
    6563    }
     
    7371
    7472    tr_bencInitDict( &top, 5 );
    75     tr_bencDictAddInt( &top, "uploaded-bytes",   s->uploadedBytes );
    7673    tr_bencDictAddInt( &top, "downloaded-bytes", s->downloadedBytes );
    7774    tr_bencDictAddInt( &top, "files-added",      s->filesAdded );
     75    tr_bencDictAddInt( &top, "seconds-active",   s->secondsActive );
    7876    tr_bencDictAddInt( &top, "session-count",    s->sessionCount );
    79     tr_bencDictAddInt( &top, "seconds-active",   s->secondsActive );
     77    tr_bencDictAddInt( &top, "uploaded-bytes",   s->uploadedBytes );
    8078
    8179    getFilename( handle, filename, sizeof(filename) );
     
    114112getStats( const tr_handle * handle )
    115113{
    116     static struct tr_stats_handle nullObject;
    117 
    118     return handle && handle->sessionStats
    119         ? handle->sessionStats
    120         : &nullObject;
     114    return handle->sessionStats;
    121115}
    122116
     
    150144{
    151145    const struct tr_stats_handle * stats = getStats( handle );
     146    assert( stats != NULL );
    152147    *setme = stats->single;
    153148    setme->secondsActive = time( NULL ) - stats->startTime;
     
    159154                              tr_session_stats  * setme )
    160155{
     156    const struct tr_stats_handle * stats = getStats( handle );
     157    assert( stats != NULL );
    161158    tr_session_stats current;
    162159    tr_sessionGetStats( handle, &current );
    163     addStats( setme, &getStats(handle)->old, &current );
     160    addStats( setme, &stats->old, &current );
    164161}
    165162
     
    186183tr_statsAddUploaded( tr_handle * handle, uint32_t bytes )
    187184{
    188     getStats(handle)->single.uploadedBytes += bytes;
     185    struct tr_stats_handle * s;
     186    if(( s = getStats( handle )))
     187        s->single.uploadedBytes += bytes;
    189188}
    190189
     
    192191tr_statsAddDownloaded( tr_handle * handle, uint32_t bytes )
    193192{
    194     getStats(handle)->single.downloadedBytes += bytes;
     193    struct tr_stats_handle * s;
     194    if(( s = getStats( handle )))
     195        s->single.downloadedBytes += bytes;
    195196}
    196197
     
    198199tr_statsFileCreated( tr_handle * handle )
    199200{
    200     getStats(handle)->single.filesAdded++;
    201 }
     201    struct tr_stats_handle * s;
     202    if(( s = getStats( handle )))
     203        s->single.filesAdded++;
     204}
Note: See TracChangeset for help on using the changeset viewer.