Changeset 2441


Ignore:
Timestamp:
Jul 20, 2007, 3:24:04 AM (15 years ago)
Author:
charles
Message:

more work on the speed limits as hammered out w/BentMyWookie

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-inspector.c

    r2425 r2441  
    14351435
    14361436static void
     1437speed_toggled_cb( GtkToggleButton * tb, gpointer gtor, int up_or_down )
     1438{
     1439  tr_torrent_t * tor = tr_torrent_handle (gtor);
     1440  gboolean b = gtk_toggle_button_get_active(tb);
     1441  tr_torrentSetSpeedMode( tor, up_or_down, b ? TR_SPEEDLIMIT_SINGLE
     1442                                             : TR_SPEEDLIMIT_GLOBAL );
     1443}
     1444static void
    14371445ul_speed_toggled_cb (GtkToggleButton *tb, gpointer gtor)
    14381446{
    1439   tr_torrent_set_upload_cap_enabled (TR_TORRENT(gtor),
    1440                                      gtk_toggle_button_get_active(tb));
    1441 }
    1442 
     1447  speed_toggled_cb( tb, gtor, TR_UP );
     1448}
    14431449static void
    14441450dl_speed_toggled_cb (GtkToggleButton *tb, gpointer gtor)
    14451451{
    1446   tr_torrent_set_download_cap_enabled (TR_TORRENT(gtor),
    1447                                        gtk_toggle_button_get_active(tb));
    1448 }
     1452  speed_toggled_cb( tb, gtor, TR_DOWN );
     1453}
     1454
    14491455
    14501456static void
     
    14631469
    14641470static void
     1471setSpeedLimit( GtkSpinButton* spin, gpointer gtor, int up_or_down )
     1472{
     1473  tr_torrent_t * tor = tr_torrent_handle (gtor);
     1474  int KiB_sec = gtk_spin_button_get_value_as_int (spin);
     1475  tr_torrentSetSpeedLimit( tor, up_or_down, KiB_sec );
     1476}
     1477static void
    14651478ul_speed_spun_cb (GtkSpinButton *spin, gpointer gtor)
    14661479{
    1467   tr_torrent_set_upload_cap_speed (TR_TORRENT(gtor),
    1468                                    gtk_spin_button_get_value_as_int (spin));
    1469 }
    1470 
     1480  setSpeedLimit( spin, gtor, TR_UP );
     1481}
    14711482static void
    14721483dl_speed_spun_cb (GtkSpinButton *spin, gpointer gtor)
    14731484{
    1474   tr_torrent_set_download_cap_speed (TR_TORRENT(gtor),
    1475                                      gtk_spin_button_get_value_as_int (spin));
     1485  setSpeedLimit( spin, gtor, TR_DOWN );
    14761486}
    14771487
     
    14861496options_page_new ( TrTorrent * gtor )
    14871497{
    1488   int row;
     1498  int i, row;
     1499  gboolean b;
    14891500  GtkAdjustment *a;
    14901501  GtkWidget *t, *w, *tb;
     1502  tr_torrent_t * tor = tr_torrent_handle (gtor);
    14911503
    14921504  row = 0;
     
    14961508
    14971509    tb = gtk_check_button_new_with_mnemonic (_("Limit _Download Speed (KiB/s):"));
    1498     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), gtor->dl_cap_enabled);
     1510    b = tr_torrentGetSpeedMode(tor,TR_DOWN) == TR_SPEEDLIMIT_SINGLE;
     1511    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), b );
    14991512    g_signal_connect (tb, "toggled", G_CALLBACK(dl_speed_toggled_cb), gtor);
    1500     a = (GtkAdjustment*) gtk_adjustment_new (gtor->dl_cap, 0.0, G_MAXDOUBLE, 1, 1, 1);
     1513
     1514    i = tr_torrentGetSpeedLimit( tor, TR_DOWN );
     1515    a = (GtkAdjustment*) gtk_adjustment_new (i, 0.0, G_MAXDOUBLE, 1, 1, 1);
    15011516    w = gtk_spin_button_new (a, 1, 0);
    15021517    g_signal_connect (w, "value-changed", G_CALLBACK(dl_speed_spun_cb), gtor);
     
    15061521
    15071522    tb = gtk_check_button_new_with_mnemonic (_("Limit _Upload Speed (KiB/s):"));
    1508     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), gtor->ul_cap_enabled);
     1523    b = tr_torrentGetSpeedMode(tor,TR_UP) == TR_SPEEDLIMIT_SINGLE;
     1524    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tb), b );
    15091525    g_signal_connect (tb, "toggled", G_CALLBACK(ul_speed_toggled_cb), gtor);
    1510     a = (GtkAdjustment*) gtk_adjustment_new (gtor->ul_cap, 0.0, G_MAXDOUBLE, 1, 1, 1);
     1526
     1527    i = tr_torrentGetSpeedLimit( tor, TR_UP );
     1528    a = (GtkAdjustment*) gtk_adjustment_new (i, 0.0, G_MAXDOUBLE, 1, 1, 1);
    15111529    w = gtk_spin_button_new (a, 1, 0);
    15121530    g_signal_connect (w, "value-changed", G_CALLBACK(ul_speed_spun_cb), gtor);
  • trunk/gtk/tr_torrent.c

    r2400 r2441  
    138138  self->severed = FALSE;
    139139  self->disposed = FALSE;
    140   self->ul_cap_enabled = FALSE;
    141   self->ul_cap = 0;
    142   self->dl_cap_enabled = FALSE;
    143   self->dl_cap = 0;
    144140}
    145141
     
    156152      g_assert(NULL == self->handle);
    157153      self->handle = g_value_get_pointer(value);
    158       if( self->handle ) {
    159           self->ul_cap         = tr_torrentGetMaxSpeedUL       ( self->handle );
    160           self->ul_cap_enabled = tr_torrentIsMaxSpeedEnabledUL ( self->handle );
    161           self->dl_cap         = tr_torrentGetMaxSpeedDL       ( self->handle );
    162           self->dl_cap_enabled = tr_torrentIsMaxSpeedEnabledDL ( self->handle );
    163       }
    164154      if(NULL != self->handle && NULL != self->dir)
    165155        tr_torrent_set_folder(self);
     
    491481                    (refreshStat(tor)->status & TR_STATUS_INACTIVE) ? 1 : 0);
    492482    tr_bencInitInt( tr_bencDictAdd( state, "seeding-cap-ratio" ),
    493                     (int)(tor->dl_cap * 100.0)); /* two decimal places */
     483                    (int)(tor->seeding_cap * 100.0)); /* two decimal places */
    494484    tr_bencInitInt( tr_bencDictAdd( state, "seeding-cap-enabled" ),
    495485                    tor->seeding_cap_enabled ? 1 : 0);
     
    525515    g_free(wd);
    526516  }
    527 }
    528 
    529 static void
    530 refresh_upload_cap ( TrTorrent *gtor )
    531 {
    532   tr_torrentEnableMaxSpeedUL( gtor->handle, gtor->ul_cap_enabled );
    533   tr_torrentSetMaxSpeedUL( gtor->handle, gtor->ul_cap );
    534 }
    535 void
    536 tr_torrent_set_upload_cap_speed ( TrTorrent *gtor, int KiB_sec )
    537 {
    538   gtor->ul_cap = KiB_sec;
    539   refresh_upload_cap ( gtor );
    540 }
    541 void
    542 tr_torrent_set_upload_cap_enabled ( TrTorrent *gtor, gboolean b )
    543 {
    544   gtor->ul_cap_enabled = b;
    545   refresh_upload_cap ( gtor );
    546 }
    547 
    548 static void
    549 refresh_download_cap ( TrTorrent *gtor )
    550 {
    551   tr_torrentEnableMaxSpeedDL( gtor->handle, gtor->dl_cap_enabled );
    552   tr_torrentSetMaxSpeedDL( gtor->handle, gtor->dl_cap );
    553 }
    554 void
    555 tr_torrent_set_download_cap_speed ( TrTorrent *gtor, int KiB_sec )
    556 {
    557   gtor->dl_cap = KiB_sec;
    558   refresh_download_cap( gtor );
    559 }
    560 void
    561 tr_torrent_set_download_cap_enabled ( TrTorrent *gtor, gboolean b )
    562 {
    563   gtor->dl_cap_enabled = b;
    564   refresh_download_cap( gtor );
    565517}
    566518
  • trunk/gtk/tr_torrent.h

    r2400 r2441  
    6363  gboolean severed;
    6464  gboolean disposed;
    65   gboolean ul_cap_enabled;
    66   gboolean dl_cap_enabled;
    6765  gboolean seeding_cap_enabled;
    68   gint ul_cap; /* KiB/sec */
    69   gint dl_cap; /* KiB/sec */
    7066  gdouble seeding_cap; /* ratio to stop seeding at */
    7167};
     
    9591char*
    9692tr_torrent_status_str ( TrTorrent * tor );
    97 
    98 void
    99 tr_torrent_set_upload_cap_speed ( TrTorrent*, int KiB_sec );
    100 void
    101 tr_torrent_set_upload_cap_enabled ( TrTorrent*, gboolean );
    102 
    103 void
    104 tr_torrent_set_download_cap_speed ( TrTorrent*, int KiB_sec );
    105 void
    106 tr_torrent_set_download_cap_enabled ( TrTorrent*, gboolean );
    10793
    10894void
  • trunk/libtransmission/fastresume.c

    r2429 r2441  
    7676
    7777    /* transfer speeds
    78      * uint32_t: the dl speed rate to use when the flag is true
    79      * char: t,f for whether or not dl speed is capped
    80      * uint32_t: the ul speed rate to use when the flag is true
    81      * char: t,f for whether or not ul speed is capped
     78     * uint32_t: dl speed rate to use when the mode is single
     79     * uint32_t: dl's tr_speedlimit_t
     80     * uint32_t: ul speed rate to use when the mode is single
     81     * uint32_t: ul's tr_speedlimit_t
    8282     */
    8383    FR_ID_SPEED = 7
     
    228228    if( TRUE )
    229229    {
    230         const int len = ( sizeof(uint32_t) + sizeof(char) ) * 2;
     230        const int len = sizeof(uint32_t) * 4;
    231231        char * buf = tr_new0( char, len );
    232232        char * walk = buf;
    233         char enabled;
    234233        uint32_t i;
    235234
    236         i = (uint32_t) tr_torrentGetMaxSpeedDL( tor );
     235        i = (uint32_t) tr_torrentGetSpeedLimit( tor, TR_DOWN );
    237236        memcpy( walk, &i, 4 ); walk += 4;
    238         enabled = tr_torrentIsMaxSpeedEnabledDL( tor ) ? 't' : 'f';
    239         *walk++ = enabled;
    240 
    241         i = (uint32_t) tr_torrentGetMaxSpeedUL( tor );
     237        i = (uint32_t) tr_torrentGetSpeedMode( tor, TR_DOWN );
    242238        memcpy( walk, &i, 4 ); walk += 4;
    243         enabled = tr_torrentIsMaxSpeedEnabledUL( tor ) ? 't' : 'f';
    244         *walk++ = enabled;
     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;
    245243
    246244        assert( walk - buf == len );
     
    275273loadSpeeds( tr_torrent_t * tor, FILE * file )
    276274{
    277     const size_t len = 2 * (sizeof(uint32_t) + sizeof(char));
     275    const size_t len = sizeof(uint32_t) * 4;
    278276    char * buf = tr_new0( char, len );
    279277    char * walk = buf;
    280     uint32_t rate;
     278    uint32_t i;
    281279    char enabled;
    282280
     
    287285    }
    288286
    289     memcpy( &rate, walk, 4 ); walk += 4;
    290     memcpy( &enabled, walk, 1 ); walk += 1;
    291     tr_torrentSetMaxSpeedDL( tor, rate );
    292     tr_torrentEnableMaxSpeedDL( tor, enabled=='t' );
    293 
    294     memcpy( &rate, walk, 4 ); walk += 4;
    295     memcpy( &enabled, walk, 1 ); walk += 1;
    296     tr_torrentSetMaxSpeedUL( tor, rate );
    297     tr_torrentEnableMaxSpeedUL( tor, enabled=='t' );
     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 );
    298295
    299296    tr_free( buf );
     
    518515            case FR_ID_SPEED:
    519516                /*  read speed data */
    520                 if( len == (uint32_t)(2*sizeof(uint32_t)+2) )
     517                if( len == (uint32_t)(sizeof(uint32_t)*4) )
    521518                {
    522519                    ret = loadSpeeds( tor, file );
  • trunk/libtransmission/internal.h

    r2430 r2441  
    162162    tr_info_t info;
    163163
    164     int                customUploadLimit;
    165     int                customDownloadLimit;
     164    tr_speedlimit_t    uploadLimitMode;
     165    tr_speedlimit_t    downloadLimitMode;
    166166    tr_ratecontrol_t * upload;
    167167    tr_ratecontrol_t * download;
  • trunk/libtransmission/peer.c

    r2428 r2441  
    378378        if( tor )
    379379        {
    380             if( tor->customDownloadLimit
    381                 ? !tr_rcCanTransfer( tor->download )
    382                 : !tr_rcCanTransfer( tor->handle->download ) )
    383             {
     380            int canDL;
     381            switch( tor->downloadLimitMode ) {
     382                case TR_SPEEDLIMIT_GLOBAL: canDL = tr_rcCanTransfer( tor->handle->download ); break;
     383                case TR_SPEEDLIMIT_SINGLE: canDL = tr_rcCanTransfer( tor->download ); break;
     384                default: canDL = TRUE; /* unlimited */
     385            }
     386            if( !canDL )
    384387                break;
    385             }
    386388        }
    387389
     
    581583    while( ( p = blockPending( tor, peer, &size ) ) )
    582584    {
     585        int canUL;
     586
    583587        if( SWIFT_ENABLED && !isSeeding && (peer->credit<0) )
    584             break;
    585 
    586         if( tor->customUploadLimit
    587             ? !tr_rcCanTransfer( tor->upload )
    588             : !tr_rcCanTransfer( tor->handle->upload ) )
     588            canUL = FALSE;
     589        else switch( tor->uploadLimitMode ) {
     590            case TR_SPEEDLIMIT_GLOBAL: canUL = tr_rcCanTransfer( tor->handle->upload ); break;
     591            case TR_SPEEDLIMIT_SINGLE: canUL = tr_rcCanTransfer( tor->upload ); break;
     592            default: canUL = TRUE; /* unlimited */
     593        }
     594        if( !canUL )
    589595            break;
    590596
     
    856862    tr_rcTransferred( peer->download, byteCount );
    857863    tr_rcTransferred( tor->download, byteCount );
    858     if ( !tor->customUploadLimit )
    859         tr_rcTransferred( tor->handle->download, byteCount );
     864    tr_rcTransferred( tor->handle->download, byteCount );
    860865
    861866    peer->credit += (int)(byteCount * SWIFT_REPAYMENT_RATIO);
     
    873878    tr_rcTransferred( peer->upload, byteCount );
    874879    tr_rcTransferred( tor->upload, byteCount );
    875     if ( !tor->customDownloadLimit )
    876         tr_rcTransferred( tor->handle->upload, byteCount );
     880    tr_rcTransferred( tor->handle->upload, byteCount );
    877881
    878882    peer->credit -= byteCount;
  • trunk/libtransmission/torrent.c

    r2430 r2441  
    6868
    6969void
    70 tr_torrentEnableMaxSpeedUL( tr_torrent_t * tor, char doThrottle )
    71 {
    72     tor->customUploadLimit = doThrottle;
    73 }
     70tr_torrentSetSpeedMode( tr_torrent_t     * tor,
     71                        int                up_or_down,
     72                        tr_speedlimit_t    mode )
     73{
     74    tr_speedlimit_t * limit = up_or_down==TR_UP
     75        ? &tor->uploadLimitMode
     76        : &tor->downloadLimitMode;
     77    *limit = mode;
     78}
     79
     80tr_speedlimit_t
     81tr_torrentGetSpeedMode( const tr_torrent_t * tor,
     82                        int                  up_or_down)
     83{
     84    return up_or_down==TR_UP ? tor->uploadLimitMode
     85                             : tor->downloadLimitMode;
     86}
     87
    7488void
    75 tr_torrentEnableMaxSpeedDL( tr_torrent_t * tor, char doThrottle )
    76 {
    77     tor->customDownloadLimit = doThrottle;
    78 }
    79 void
    80 tr_torrentSetMaxSpeedUL( tr_torrent_t * tor, int KiB_sec )
    81 {
    82     tr_rcSetLimit( tor->upload, KiB_sec );
    83 }
    84 void
    85 tr_torrentSetMaxSpeedDL( tr_torrent_t * tor, int KiB_sec )
    86 {
    87     tr_rcSetLimit( tor->download, KiB_sec );
    88 }
     89tr_torrentSetSpeedLimit( tr_torrent_t   * tor,
     90                         int              up_or_down,
     91                         int              single_KiB_sec )
     92{
     93    tr_ratecontrol_t * rc = up_or_down==TR_UP ? tor->upload : tor->download;
     94    tr_rcSetLimit( rc, single_KiB_sec );
     95}
     96
    8997int
    90 tr_torrentIsMaxSpeedEnabledUL( const tr_torrent_t * tor )
    91 {
    92     return tor->customUploadLimit;
    93 }
    94 int
    95 tr_torrentIsMaxSpeedEnabledDL( const tr_torrent_t * tor )
    96 {
    97     return tor->customDownloadLimit;
    98 }
    99 int
    100 tr_torrentGetMaxSpeedUL( const tr_torrent_t * tor )
    101 {
    102     return tr_rcGetLimit( tor->upload );
    103 }
    104 int
    105 tr_torrentGetMaxSpeedDL( const tr_torrent_t * tor )
    106 {
    107     return tr_rcGetLimit( tor->download );
     98tr_torrentGetSpeedLimit( const tr_torrent_t  * tor,
     99                         int                   up_or_down )
     100{
     101    tr_ratecontrol_t * rc = up_or_down==TR_UP ? tor->upload : tor->download;
     102    return tr_rcGetLimit( rc );
    108103}
    109104
  • trunk/libtransmission/transmission.h

    r2396 r2441  
    197197void tr_torrentIterate( tr_handle_t *, tr_callback_t, void * );
    198198
    199 /**
    200 *** Speed Throttle
     199
     200/***********************************************************************
     201*** Speed Limits
    201202**/
    202203
    203 void tr_torrentEnableMaxSpeedUL ( tr_torrent_t * , char doThrottle );
    204 void tr_torrentEnableMaxSpeedDL ( tr_torrent_t * , char doThrottle );
    205 void tr_torrentSetMaxSpeedUL    ( tr_torrent_t * , int KiB_sec );
    206 void tr_torrentSetMaxSpeedDL    ( tr_torrent_t * , int KiB_sec );
    207 
    208 int tr_torrentIsMaxSpeedEnabledUL ( const tr_torrent_t * );
    209 int tr_torrentIsMaxSpeedEnabledDL ( const tr_torrent_t * );
    210 int tr_torrentGetMaxSpeedUL       ( const tr_torrent_t * );
    211 int tr_torrentGetMaxSpeedDL       ( const tr_torrent_t * );
     204typedef enum
     205{
     206    TR_SPEEDLIMIT_GLOBAL,    /* indirectly follow the global pool's limit */
     207    TR_SPEEDLIMIT_SINGLE,    /* directly follow tr_torrentSetMaxSpeed() */
     208    TR_SPEEDLIMIT_UNLIMITED  /* no limits at all */
     209}
     210tr_speedlimit_t;
     211
     212enum { TR_UP, TR_DOWN };
     213
     214void tr_torrentSetSpeedMode( tr_torrent_t     * tor,
     215                             int                up_or_down,
     216                             tr_speedlimit_t    mode );
     217
     218tr_speedlimit_t tr_torrentGetSpeedMode( const tr_torrent_t * tor,
     219                                        int                  up_or_down);
     220
     221void tr_torrentSetSpeedLimit( tr_torrent_t   * tor,
     222                              int              up_or_down,
     223                              int              single_KiB_sec );
     224
     225int tr_torrentGetSpeedLimit( const tr_torrent_t  * tor,
     226                             int                   up_or_down );
    212227
    213228/***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.