Ignore:
Timestamp:
Nov 25, 2008, 9:35:17 PM (14 years ago)
Author:
charles
Message:

(libT) yet another stab at getting bandwidth management under control. this version may suck less than previous attempts. It also breaks the mac build until someone adds iobuf.[ch] to xcode...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7147 r7154  
    144144void
    145145tr_torrentSetSpeedMode( tr_torrent *  tor,
    146                         tr_direction  direction,
     146                        tr_direction  dir,
    147147                        tr_speedlimit mode )
    148148{
    149     tr_speedlimit * limit = direction == TR_UP ? &tor->uploadLimitMode
    150                                                : &tor->downloadLimitMode;
    151 
    152     *limit = mode;
     149    assert( tor != NULL );
     150    assert( dir==TR_UP || dir==TR_DOWN );
     151    assert( mode==TR_SPEEDLIMIT_GLOBAL || mode==TR_SPEEDLIMIT_SINGLE || mode==TR_SPEEDLIMIT_UNLIMITED  );
     152
     153    tor->speedLimitMode[dir] = mode;
     154
     155    tr_bandwidthSetLimited( tor->bandwidth, dir, mode==TR_SPEEDLIMIT_SINGLE );
     156    tr_bandwidthHonorParentLimits( tor->bandwidth, dir, mode!=TR_SPEEDLIMIT_UNLIMITED );
    153157}
    154158
    155159tr_speedlimit
    156160tr_torrentGetSpeedMode( const tr_torrent * tor,
    157                         tr_direction       direction )
    158 {
    159     return direction == TR_UP ? tor->uploadLimitMode
    160                               : tor->downloadLimitMode;
     161                        tr_direction       dir )
     162{
     163    assert( tor != NULL );
     164    assert( dir==TR_UP || dir==TR_DOWN );
     165
     166    return tor->speedLimitMode[dir];
    161167}
    162168
    163169void
    164170tr_torrentSetSpeedLimit( tr_torrent * tor,
    165                          tr_direction direction,
    166                          int          single_KiB_sec )
    167 {
    168     switch( direction )
    169     {
    170         case TR_UP:
    171             tor->uploadLimit = single_KiB_sec; break;
    172 
    173         case TR_DOWN:
    174             tor->downloadLimit = single_KiB_sec; break;
    175 
    176         default:
    177             assert( 0 );
    178     }
     171                         tr_direction dir,
     172                         int          desiredSpeed )
     173{
     174    tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, desiredSpeed );
    179175}
    180176
    181177int
    182178tr_torrentGetSpeedLimit( const tr_torrent * tor,
    183                          tr_direction       direction )
    184 {
    185     switch( direction )
    186     {
    187         case TR_UP:
    188             return tor->uploadLimit;
    189 
    190         case TR_DOWN:
    191             return tor->downloadLimit;
    192 
    193         default:
    194             assert( 0 );
    195     }
     179                         tr_direction       dir )
     180{
     181    return tr_bandwidthGetDesiredSpeed( tor->bandwidth, dir );
    196182}
    197183
     
    498484    randomizeTiers( info );
    499485
    500     tor->bandwidth[TR_UP] = tr_bandwidthNew( h );
    501     tor->bandwidth[TR_DOWN] = tr_bandwidthNew( h );
     486    tor->bandwidth = tr_bandwidthNew( h, h->bandwidth );
     487
     488fprintf( stderr, "torrent [%s] bandwidth is %p\n", info->name, tor->bandwidth );
    502489
    503490    tor->blockSize = getBlockSize( info->pieceSize );
     
    541528    tr_torrentInitFilePieces( tor );
    542529
    543     tor->uploadLimit = 0;
    544     tor->downloadLimit = 0;
    545530    tor->swarmSpeed = tr_rcInit( );
    546531
     
    814799                            s->peersFrom );
    815800
    816     s->rawUploadSpeed     = tr_bandwidthGetRawSpeed  ( tor->bandwidth[TR_UP] );
    817     s->rawDownloadSpeed   = tr_bandwidthGetRawSpeed  ( tor->bandwidth[TR_DOWN] );
    818     s->pieceUploadSpeed   = tr_bandwidthGetPieceSpeed( tor->bandwidth[TR_UP] );
    819     s->pieceDownloadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth[TR_DOWN] );
     801    s->rawUploadSpeed     = tr_bandwidthGetRawSpeed  ( tor->bandwidth, TR_UP );
     802    s->rawDownloadSpeed   = tr_bandwidthGetRawSpeed  ( tor->bandwidth, TR_DOWN );
     803    s->pieceUploadSpeed   = tr_bandwidthGetPieceSpeed( tor->bandwidth, TR_UP );
     804    s->pieceDownloadSpeed = tr_bandwidthGetPieceSpeed( tor->bandwidth, TR_DOWN );
    820805
    821806    usableSeeds += tor->info.webseedCount;
     
    11001085    h->torrentCount--;
    11011086
    1102     tr_bandwidthFree( tor->bandwidth[TR_DOWN] );
    1103     tr_bandwidthFree( tor->bandwidth[TR_UP] );
     1087    tr_bandwidthFree( tor->bandwidth );
    11041088
    11051089    tr_metainfoFree( inf );
Note: See TracChangeset for help on using the changeset viewer.