Changeset 3492


Ignore:
Timestamp:
Oct 21, 2007, 3:47:26 PM (14 years ago)
Author:
charles
Message:

fix ul/dl speed wart reported by BentMyWookie?

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/internal.h

    r3470 r3492  
    7070tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
    7171
     72void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
     73
    7274/* get the index of this piece's first block */
    7375#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
  • trunk/libtransmission/peer-mgr.c

    r3469 r3492  
    12821282}
    12831283
     1284int
     1285tr_peerMgrHasConnections( const tr_peerMgr * manager,
     1286                          const uint8_t    * torrentHash )
     1287{
     1288    int ret;
     1289    const Torrent * t;
     1290    managerLock( (tr_peerMgr*)manager );
     1291
     1292    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
     1293    ret = t && tr_ptrArraySize( t->peers );
     1294
     1295    managerUnlock( (tr_peerMgr*)manager );
     1296    return ret;
     1297}
     1298
    12841299void
    12851300tr_peerMgrTorrentStats( const tr_peerMgr * manager,
  • trunk/libtransmission/peer-mgr.h

    r3428 r3492  
    8383                                            const uint8_t    * torrentHash );
    8484
     85int tr_peerMgrHasConnections( const tr_peerMgr * manager,
     86                              const uint8_t    * torrentHash );
     87
    8588void tr_peerMgrTorrentStats( const tr_peerMgr * manager,
    8689                             const uint8_t    * torrentHash,
  • trunk/libtransmission/torrent.c

    r3482 r3492  
    654654}
    655655
     656/* rcRate's averaging code can make it appear that we're
     657 * still sending bytes after a torrent stops or all the
     658 * peers disconnect, so short-circuit that appearance here */
     659void
     660tr_torrentGetRates( const tr_torrent * tor,
     661                    float            * toClient,
     662                    float            * toPeer)
     663{
     664    const int showSpeed = tor->isRunning
     665        && tr_peerMgrHasConnections( tor->handle->peerMgr, tor->info.hash );
     666
     667    if( toClient )
     668        *toClient = showSpeed ? tr_rcRate( tor->download ) : 0.0;
     669    if( toPeer )
     670        *toPeer = showSpeed ? tr_rcRate( tor->upload ) : 0.0;
     671}
     672
     673
    656674const tr_stat *
    657675tr_torrentStat( tr_torrent * tor )
     
    704722        : 1.0 - ((double)tr_bitfieldCountTrueBits(tor->uncheckedPieces) / tor->info.pieceCount);
    705723
    706     /* rcRate's averaging code can make it appear that we're
    707      * still sending bytes after a torrent stops or all the
    708      * peers disconnect, so short-circuit that appearance here */
    709     if( tor->isRunning && s->peersConnected ) {
    710         s->rateDownload = tr_rcRate( tor->download );
    711         s->rateUpload = tr_rcRate( tor->upload );
    712     } else {
    713         s->rateDownload = 0.0;
    714         s->rateUpload = 0.0;
    715     }
     724    tr_torrentGetRates( tor, &s->rateDownload, &s->rateUpload );
    716725   
    717726    tr_trackerGetCounts( tc,
  • trunk/libtransmission/transmission.c

    r3469 r3492  
    260260
    261261void
    262 tr_torrentRates( tr_handle * h, float * dl, float * ul )
    263 {
    264     tr_torrent * tor;
     262tr_torrentRates( tr_handle * h, float * toClient, float * toPeer )
     263{
     264    const tr_torrent * tor;
    265265    tr_globalLock( h );
    266266
    267     *dl = *ul = 0.0;
     267    *toClient = *toPeer = 0.0;
    268268    for( tor = h->torrentList; tor; tor = tor->next )
    269269    {
    270         *dl += tr_rcRate( tor->download );
    271         *ul += tr_rcRate( tor->upload );
     270        float c, p;
     271        tr_torrentGetRates( tor, &c, &p );
     272        *toClient += c;
     273        *toPeer += p;
    272274    }
    273275
Note: See TracChangeset for help on using the changeset viewer.