diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index c728fcf73..b9bb0125f 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -322,7 +322,7 @@ tr_bandwidthSetPeer( tr_bandwidth * b, tr_peerIo * peer ) static unsigned int bandwidthClamp( const tr_bandwidth * b, - const uint64_t now, + uint64_t now, tr_direction dir, unsigned int byteCount ) { @@ -339,9 +339,16 @@ bandwidthClamp( const tr_bandwidth * b, * clamp down harder on the bytes available */ if( byteCount > 0 ) { - double current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN ); - double desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN ); - double r = desired >= 1 ? current / desired : 0; + double current; + double desired; + double r; + + if( now == 0 ) + now = tr_time_msec( ); + + current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN ); + desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN ); + r = desired >= 1 ? current / desired : 0; if( r > 1.0 ) byteCount = 0; else if( r > 0.9 ) byteCount *= 0.8; @@ -360,8 +367,7 @@ tr_bandwidthClamp( const tr_bandwidth * b, tr_direction dir, unsigned int byteCount ) { - const uint64_t now_msec = tr_time_msec( ); - return bandwidthClamp( b, now_msec, dir, byteCount ); + return bandwidthClamp( b, 0, dir, byteCount ); }