Changeset 8089


Ignore:
Timestamp:
Mar 25, 2009, 7:50:58 PM (13 years ago)
Author:
charles
Message:

(trunk libT) modification to r8088 at livings1's request: make sure the alternate speed test takes place at the top of the minute

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r8088 r8089  
    2020#include <unistd.h> /* stat */
    2121#include <dirent.h> /* opendir */
     22
     23#include <event.h>
    2224
    2325#include "transmission.h"
     
    380382static void metainfoLookupRescan( tr_session * );
    381383static void tr_sessionInitImpl( void * );
    382 static int onBandwidthTimer( void * );
     384static void onAltTimer( int, short, void* );
     385
     386/* set the alt-speed timer to go off at the top of the minute */
     387static void
     388setAltTimer( tr_session * session )
     389{
     390    const time_t now = time( NULL );
     391    struct tm tm;
     392    struct timeval tv;
     393
     394    assert( tr_isSession( session ) );
     395    assert( session->altTimer != NULL );
     396
     397    tr_localtime_r( &now, &tm );
     398    tv.tv_sec = 60 - tm.tm_sec;
     399    tv.tv_usec = 0;
     400    evtimer_add( session->altTimer, &tv );
     401}
    383402
    384403struct init_data
     
    619638    assert( tr_isSession( session ) );
    620639
    621     session->bandwidthTimer = tr_timerNew( session, onBandwidthTimer, session, 60000 );
     640    session->altTimer = tr_new0( struct event, 1 );
     641    evtimer_set( session->altTimer, onAltTimer, session );
     642    setAltTimer( session );
    622643
    623644    /* first %s is the application name
     
    861882 * (1) update session->isAltTime
    862883 * (2) alter the speed limits when the alt limits go on and off */
    863 static int
    864 onBandwidthTimer( void * vsession )
    865 {
     884static void
     885onAltTimer( int foo UNUSED, short bar UNUSED, void * vsession )
     886{
     887    tr_bool wasAltTime;
    866888    tr_session * session = vsession;
    867     tr_bool wasAltTime;
    868889
    869890    assert( tr_isSession( session ) );
     
    881902    }
    882903
    883     return TRUE; /* invoke again when another minute's passed */
     904    setAltTimer( session );
    884905}
    885906
     
    934955}
    935956
     957static void
     958checkAltTime( void * session )
     959{
     960    onAltTimer( 0, 0, session );
     961}
     962
    936963void
    937964tr_sessionSetAltSpeedLimitEnabled( tr_session   * session,
     
    943970    session->isAltSpeedLimited = isEnabled;
    944971
    945     onBandwidthTimer( session );
     972    tr_runInEventThread( session, checkAltTime, session );
    946973}
    947974
     
    964991
    965992    session->altSpeedLimit[dir] = desiredSpeed;
     993
    966994    updateBandwidth( session, dir );
    967995}
     
    9831011
    9841012    session->altSpeedBeginTime = minutesSinceMidnight;
     1013
     1014    tr_runInEventThread( session, checkAltTime, session );
    9851015}
    9861016
     
    9991029
    10001030    session->altSpeedEndTime = minutesSinceMidnight;
     1031
     1032    tr_runInEventThread( session, checkAltTime, session );
    10011033}
    10021034
     
    11091141    assert( tr_isSession( session ) );
    11101142
    1111     tr_timerFree( &session->bandwidthTimer );
     1143    evtimer_del( session->altTimer );
     1144    tr_free( session->altTimer );
     1145    session->altTimer = NULL;
     1146
    11121147    tr_statsClose( session );
    11131148    tr_sharedShuttingDown( session->shared );
  • trunk/libtransmission/session.h

    r8088 r8089  
    132132    int                          metainfoLookupCount;
    133133
    134     struct tr_timer            * bandwidthTimer;
     134    struct event               * altTimer;
    135135
    136136    /* the size of the output buffer for peer connections */
Note: See TracChangeset for help on using the changeset viewer.