Changeset 11949


Ignore:
Timestamp:
Feb 18, 2011, 12:43:27 AM (11 years ago)
Author:
jch
Message:

When uTP is disabled, don't call UTP_CheckTimeouts too often.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/tr-utp.c

    r11944 r11949  
    8989
    9090static void
    91 reset_timer( void )
     91reset_timer(tr_session *ss)
    9292{
    93     int sec = 0;
    94     int usec = UTP_INTERVAL_US / 2 + tr_cryptoWeakRandInt(UTP_INTERVAL_US);
     93    int sec;
     94    int usec;
     95    if( tr_sessionIsUTPEnabled( ss ) ) {
     96        sec = 0;
     97        usec = UTP_INTERVAL_US / 2 + tr_cryptoWeakRandInt(UTP_INTERVAL_US);
     98    } else {
     99        /* If somebody has disabled uTP, then we still want to run
     100           UTP_CheckTimeouts, in order to let closed sockets finish
     101           gracefully and so on.  However, since we're not particularly
     102           interested in that happening in a timely manner, we might as
     103           well use a large timeout. */
     104        sec = 2;
     105        usec = tr_cryptoWeakRandInt( 1000000 );
     106    }
    95107    tr_timerAdd( utp_timer, sec, usec );
    96108}
    97109
    98110static void
    99 timer_callback(int s UNUSED, short type UNUSED, void *closure UNUSED)
     111timer_callback(int s UNUSED, short type UNUSED, void *closure)
    100112{
     113    tr_session *ss = closure;
    101114    UTP_CheckTimeouts();
    102     reset_timer();
     115    reset_timer( ss );
    103116}
    104117
     
    110123    if(utp_timer == NULL)
    111124    {
    112         utp_timer = evtimer_new( ss->event_base, timer_callback, NULL );
     125        utp_timer = evtimer_new( ss->event_base, timer_callback, ss );
    113126        if(utp_timer == NULL)
    114127            return -1;
    115         reset_timer();
     128        reset_timer( ss );
    116129    }
    117130
Note: See TracChangeset for help on using the changeset viewer.