Ignore:
Timestamp:
Dec 13, 2008, 10:52:15 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #1593: Setting upload to 0 kills all download

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r7352 r7366  
    288288
    289289    h->bandwidth = tr_bandwidthNew( h, NULL );
    290     tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_UP, uploadLimit );
    291     tr_bandwidthSetDesiredSpeed( h->bandwidth, TR_DOWN, downloadLimit );
    292     tr_bandwidthSetLimited( h->bandwidth, TR_UP, useUploadLimit );
    293     tr_bandwidthSetLimited( h->bandwidth, TR_DOWN, useDownloadLimit );
     290    tr_sessionSetSpeedLimit       ( h, TR_UP,  uploadLimit );
     291    tr_sessionSetSpeedLimitEnabled( h, TR_UP,   useUploadLimit );
     292    tr_sessionSetSpeedLimit       ( h, TR_DOWN, downloadLimit );
     293    tr_sessionSetSpeedLimitEnabled( h, TR_DOWN, useDownloadLimit );
    294294
    295295    /* first %s is the application name
     
    457457***/
    458458
     459static void
     460updateBandwidth( tr_session * session, tr_direction dir )
     461{
     462    const tr_bool zeroCase = session->speedLimit[dir] < 1 && session->isSpeedLimited[dir];
     463
     464    tr_bandwidthSetLimited( session->bandwidth, dir, session->isSpeedLimited[dir] && !zeroCase );
     465
     466    tr_bandwidthSetDesiredSpeed( session->bandwidth, dir, session->speedLimit[dir] );
     467}
     468
    459469void
    460470tr_sessionSetSpeedLimitEnabled( tr_session      * session,
    461471                                tr_direction      dir,
    462                                 int               isLimited )
    463 {
    464     tr_bandwidthSetLimited( session->bandwidth, dir, isLimited );
    465 }
    466 
    467 int
    468 tr_sessionIsSpeedLimitEnabled( const tr_session  * session,
    469                                tr_direction        dir )
    470 {
    471     return tr_bandwidthIsLimited( session->bandwidth, dir );
     472                                tr_bool           isLimited )
     473{
     474    assert( session );
     475    assert( dir==TR_UP || dir==TR_DOWN );
     476
     477    session->isSpeedLimited[dir] = isLimited;
     478    updateBandwidth( session, dir );
    472479}
    473480
     
    477484                         int             desiredSpeed )
    478485{
    479     tr_bandwidthSetDesiredSpeed( session->bandwidth, dir, desiredSpeed );
     486    assert( session );
     487    assert( dir==TR_UP || dir==TR_DOWN );
     488
     489    session->speedLimit[dir] = desiredSpeed;
     490    updateBandwidth( session, dir );
     491}
     492
     493tr_bool
     494tr_sessionIsSpeedLimitEnabled( const tr_session  * session,
     495                               tr_direction        dir )
     496{
     497    assert( session );
     498    assert( dir==TR_UP || dir==TR_DOWN );
     499
     500    return session->isSpeedLimited[dir];
    480501}
    481502
     
    484505                         tr_direction        dir )
    485506{
    486     return tr_bandwidthGetDesiredSpeed( session->bandwidth, dir );
     507    assert( session );
     508    assert( dir==TR_UP || dir==TR_DOWN );
     509
     510    return session->speedLimit[dir];
    487511}
    488512
Note: See TracChangeset for help on using the changeset viewer.