Changeset 8698


Ignore:
Timestamp:
Jun 15, 2009, 3:24:40 AM (13 years ago)
Author:
charles
Message:

(trunk libT) simplify the evtimer / struct timeval code a little

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r8697 r8698  
    11861186                 void *             doneUserData )
    11871187{
    1188     struct timeval tv;
    11891188    tr_handshake * handshake;
    11901189
     
    11971196    handshake->session = tr_peerIoGetSession( io );
    11981197
    1199     tr_timevalSet( &tv, HANDSHAKE_TIMEOUT_SEC, 0 );
    12001198    evtimer_set( &handshake->timeout_timer, handshakeTimeout, handshake );
    1201     evtimer_add( &handshake->timeout_timer, &tv );
     1199    tr_timerAdd( &handshake->timeout_timer, HANDSHAKE_TIMEOUT_SEC, 0 );
    12021200
    12031201    tr_peerIoRef( io ); /* balanced by the unref in tr_handshakeFree */
  • trunk/libtransmission/peer-msgs.c

    r8697 r8698  
    21172117pexPulse( int foo UNUSED, short bar UNUSED, void * vmsgs )
    21182118{
    2119     struct timeval tv;
    21202119    struct tr_peermsgs * msgs = vmsgs;
    21212120
    21222121    sendPex( msgs );
    21232122
    2124     tr_timevalSet( &tv, PEX_INTERVAL_SECS, 0 );
    2125     evtimer_add( &msgs->pexTimer, &tv );
     2123    tr_timerAdd( &msgs->pexTimer, PEX_INTERVAL_SECS, 0 );
    21262124}
    21272125
     
    21382136{
    21392137    tr_peermsgs * m;
    2140     struct timeval tv;
    21412138
    21422139    assert( peer );
     
    21612158    m->clientAskedFor = REQUEST_LIST_INIT;
    21622159    m->clientWillAskFor = REQUEST_LIST_INIT;
    2163     tr_timevalSet( &tv, PEX_INTERVAL_SECS, 0 );
    21642160    evtimer_set( &m->pexTimer, pexPulse, m );
    2165     evtimer_add( &m->pexTimer, &tv );
     2161    tr_timerAdd( &m->pexTimer, PEX_INTERVAL_SECS, 0 );
    21662162    peer->msgs = m;
    21672163
  • trunk/libtransmission/port-forwarding.c

    r8681 r8698  
    9292onTimer( int fd UNUSED, short what UNUSED, void * vshared )
    9393{
     94    int sec=0, msec=0;
    9495    tr_shared * s = vshared;
    95     struct timeval interval;
    9696
    9797    assert( s );
     
    109109             * to renew the port forwarding if it's expired */
    110110            s->doPortCheck = TRUE;
    111             tr_timevalSet( &interval, 60*20, 0 );
     111            sec = 60 * 20;
    112112            break;
    113113
    114114        case TR_PORT_ERROR:
    115115            /* some kind of an error.  wait 60 seconds and retry */
    116             tr_timevalSet( &interval, 60, 0 );
     116            sec = 60;
    117117            break;
    118118
    119119        default:
    120120            /* in progress.  pulse frequently. */
    121             tr_timevalSet( &interval, 0, 333000 );
     121            msec = 333000;
    122122            break;
    123123    }
    124124
    125     assert( tr_isTimeval( &interval ) );
    126     evtimer_add( s->timer, &interval );
     125    tr_timerAdd( s->timer, sec, msec );
    127126}
    128127
     
    143142    if( isEnabled )
    144143    {
    145         struct timeval timeval;
    146 
    147144        s->timer = tr_new0( struct event, 1 );
    148145        evtimer_set( s->timer, onTimer, s );
    149         tr_timevalSet( &timeval, 0, 333000 );
    150         evtimer_add( s->timer, &timeval );
     146        tr_timerAdd( s->timer, 0, 333000 );
    151147    }
    152148
  • trunk/libtransmission/session.c

    r8681 r8698  
    10631063    const time_t now = time( NULL );
    10641064    struct tm tm;
    1065     struct timeval tv;
    10661065
    10671066    assert( tr_isSession( session ) );
     
    10691068
    10701069    tr_localtime_r( &now, &tm );
    1071     tr_timevalSet( &tv, 60-tm.tm_sec, 0 );
    1072     evtimer_add( session->altTimer, &tv );
     1070    tr_timerAdd( session->altTimer, 60-tm.tm_sec, 0 );
    10731071}
    10741072
  • trunk/libtransmission/tr-dht.c

    r8681 r8698  
    103103{
    104104    struct sockaddr_in sin;
    105     struct timeval tv;
    106105    tr_benc benc;
    107106    int rc;
     
    169168    }
    170169
    171     tr_timevalSet( &tv, 0, tr_cryptoWeakRandInt( 1000000 ) );
    172170    event_set( &dht_event, dht_socket, EV_READ, event_callback, NULL );
    173     assert( tr_isTimeval( &tv ) );
    174     event_add( &dht_event, &tv );
     171    tr_timerAdd( &dht_event, 0, tr_cryptoWeakRandInt( 1000000 ) );
    175172
    176173    return 1;
     
    361358{
    362359    time_t tosleep;
    363     struct timeval tv;
    364360
    365361    if( dht_periodic(s, type == EV_READ, &tosleep, callback, NULL) < 0 ) {
     
    376372    /* Being slightly late is fine,
    377373       and has the added benefit of adding some jitter. */
    378     tr_timevalSet( &tv, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
    379     event_add( &dht_event, &tv );
     374    tr_timerAdd( &dht_event, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
    380375}
    381376
  • trunk/libtransmission/utils.c

    r8695 r8698  
    484484}
    485485
     486void
     487tr_timerAdd( struct event * timer, int seconds, int milliseconds )
     488{
     489    struct timeval tv;
     490    tr_timevalSet( &tv, seconds, milliseconds );
     491    event_add( timer, &tv );
     492}
    486493
    487494/**
  • trunk/libtransmission/utils.h

    r8695 r8698  
    245245void tr_timevalSet( struct timeval * setme, int seconds, int microseconds );
    246246
     247struct event;
     248
     249void tr_timerAdd( struct event * timer, int seconds, int milliseconds );
     250
    247251
    248252/** @brief return the current date in milliseconds */
Note: See TracChangeset for help on using the changeset viewer.