Changeset 2443


Ignore:
Timestamp:
Jul 20, 2007, 6:08:34 AM (15 years ago)
Author:
charles
Message:

more work on speed control

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/fastresume.c

    r2441 r2443  
    8181     * uint32_t: ul's tr_speedlimit_t
    8282     */
    83     FR_ID_SPEED = 7
     83    FR_ID_SPEED = 8
    8484};
    8585
     
    9292#define FR_PROGRESS_LEN( t ) \
    9393  ( FR_MTIME_LEN( t ) + FR_BLOCK_BITFIELD_LEN( t ) )
     94#define FR_SPEED_LEN (2 * (sizeof(uint16_t) + sizeof(uint8_t) ) )
    9495
    9596static void
     
    228229    if( TRUE )
    229230    {
    230         const int len = sizeof(uint32_t) * 4;
     231        const int len = FR_SPEED_LEN;
    231232        char * buf = tr_new0( char, len );
    232233        char * walk = buf;
    233         uint32_t i;
    234 
    235         i = (uint32_t) tr_torrentGetSpeedLimit( tor, TR_DOWN );
    236         memcpy( walk, &i, 4 ); walk += 4;
    237         i = (uint32_t) tr_torrentGetSpeedMode( tor, TR_DOWN );
    238         memcpy( walk, &i, 4 ); walk += 4;
    239         i = (uint32_t) tr_torrentGetSpeedLimit( tor, TR_UP );
    240         memcpy( walk, &i, 4 ); walk += 4;
    241         i = (uint32_t) tr_torrentGetSpeedMode( tor, TR_UP );
    242         memcpy( walk, &i, 4 ); walk += 4;
     234        uint16_t i16;
     235        uint8_t i8;
     236
     237        i16 = (uint16_t) tr_torrentGetSpeedLimit( tor, TR_DOWN );
     238        memcpy( walk, &i16, 2 ); walk += 2;
     239        i8 = (uint8_t) tr_torrentGetSpeedMode( tor, TR_DOWN );
     240        memcpy( walk, &i8, 1 ); walk += 1;
     241        i16 = (uint16_t) tr_torrentGetSpeedLimit( tor, TR_UP );
     242        memcpy( walk, &i16, 2 ); walk += 2;
     243        i8 = (uint8_t) tr_torrentGetSpeedMode( tor, TR_UP );
     244        memcpy( walk, &i8, 1 ); walk += 1;
    243245
    244246        assert( walk - buf == len );
     
    273275loadSpeeds( tr_torrent_t * tor, FILE * file )
    274276{
    275     const size_t len = sizeof(uint32_t) * 4;
     277    const size_t len = FR_SPEED_LEN;
    276278    char * buf = tr_new0( char, len );
    277279    char * walk = buf;
    278     uint32_t i;
    279     char enabled;
     280    uint16_t i16;
     281    uint8_t i8;
    280282
    281283    if( len != fread( buf, 1, len, file ) ) {
     
    285287    }
    286288
    287     memcpy( &i, walk, 4 ); walk += 4;
    288     tr_torrentSetSpeedLimit( tor, TR_DOWN, i );
    289     memcpy( &i, walk, 4 ); walk += 4;
    290     tr_torrentSetSpeedMode( tor, TR_DOWN, (tr_speedlimit_t)i );
    291     memcpy( &i, walk, 4 ); walk += 4;
    292     tr_torrentSetSpeedLimit( tor, TR_UP, i );
    293     memcpy( &i, walk, 4 ); walk += 4;
    294     tr_torrentSetSpeedMode( tor, TR_UP, (tr_speedlimit_t)i );
     289    memcpy( &i16, walk, 2 ); walk += 2;
     290    tr_torrentSetSpeedLimit( tor, TR_DOWN, i16 );
     291    memcpy( &i8, walk, 1 ); walk += 1;
     292    tr_torrentSetSpeedMode( tor, TR_DOWN, (tr_speedlimit_t)i8 );
     293    memcpy( &i16, walk, 2 ); walk += 2;
     294    tr_torrentSetSpeedLimit( tor, TR_UP, i16 );
     295    memcpy( &i8, walk, 1 ); walk += 1;
     296    tr_torrentSetSpeedMode( tor, TR_UP, (tr_speedlimit_t)i8 );
    295297
    296298    tr_free( buf );
     
    515517            case FR_ID_SPEED:
    516518                /*  read speed data */
    517                 if( len == (uint32_t)(sizeof(uint32_t)*4) )
     519                if( len == FR_SPEED_LEN )
    518520                {
    519521                    ret = loadSpeeds( tor, file );
  • trunk/libtransmission/ratecontrol.c

    r2388 r2443  
    7575{
    7676    tr_ratecontrol_t * r = tr_new0( tr_ratecontrol_t, 1 );
    77     r->limit = -1;
     77    r->limit = 0;
    7878    tr_rwInit( &r->lock );
    7979    return r;
     
    9898    tr_rwReaderLock( (tr_rwlock_t*)&r->lock );
    9999
    100     if( r->limit < 0 ) /* unbounded */
    101         ret = TRUE;
    102     else if( !r->limit ) /* off */
    103         ret = FALSE;
    104     else
    105         ret = rateForInterval( r, SHORT_INTERVAL_MSEC ) < r->limit;
     100    ret = rateForInterval( r, SHORT_INTERVAL_MSEC ) < r->limit;
    106101
    107102    tr_rwReaderUnlock( (tr_rwlock_t*)&r->lock );
Note: See TracChangeset for help on using the changeset viewer.