Changeset 8681


Ignore:
Timestamp:
Jun 12, 2009, 11:01:35 PM (13 years ago)
Author:
charles
Message:

(trunk libT) possible fix for #2078: Assertion failed: (tv->tv_usec >= 0)

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/port-forwarding.c

    r8538 r8681  
    109109             * to renew the port forwarding if it's expired */
    110110            s->doPortCheck = TRUE;
    111             interval.tv_sec = 60*20;
     111            tr_timevalSet( &interval, 60*20, 0 );
    112112            break;
    113113
    114114        case TR_PORT_ERROR:
    115115            /* some kind of an error.  wait 60 seconds and retry */
    116             interval.tv_sec = 60;
     116            tr_timevalSet( &interval, 60, 0 );
    117117            break;
    118118
    119119        default:
    120120            /* in progress.  pulse frequently. */
    121             interval.tv_sec = 0;
    122             interval.tv_usec = 333000;
     121            tr_timevalSet( &interval, 0, 333000 );
    123122            break;
    124123    }
    125124
     125    assert( tr_isTimeval( &interval ) );
    126126    evtimer_add( s->timer, &interval );
    127127}
     
    144144    {
    145145        struct timeval timeval;
    146         timeval.tv_sec = 0;
    147         timeval.tv_usec = 333000;
     146
    148147        s->timer = tr_new0( struct event, 1 );
    149148        evtimer_set( s->timer, onTimer, s );
     149        tr_timevalSet( &timeval, 0, 333000 );
    150150        evtimer_add( s->timer, &timeval );
    151151    }
  • trunk/libtransmission/session.c

    r8680 r8681  
    10691069
    10701070    tr_localtime_r( &now, &tm );
    1071     tv.tv_sec = 60 - tm.tm_sec;
    1072     tv.tv_usec = 0;
     1071    tr_timevalSet( &tv, 60-tm.tm_sec, 0 );
    10731072    evtimer_add( session->altTimer, &tv );
    10741073}
  • trunk/libtransmission/tr-dht.c

    r8606 r8681  
    9292            break;
    9393        tr_dhtAddNode(cl->session, &addr, port, 1);
    94         tv.tv_sec = 2 + tr_cryptoWeakRandInt( 5 );
    95         tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
    96         select(0, NULL, NULL, NULL, &tv);
     94        tr_timevalSet( &tv, 2 + tr_cryptoWeakRandInt( 5 ), tr_cryptoWeakRandInt( 1000000 ) );
     95        select( 0, NULL, NULL, NULL, &tv );
    9796    }
    9897    tr_free( cl->nodes );
     
    170169    }
    171170
    172     tv.tv_sec = 0;
    173     tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
     171    tr_timevalSet( &tv, 0, tr_cryptoWeakRandInt( 1000000 ) );
    174172    event_set( &dht_event, dht_socket, EV_READ, event_callback, NULL );
     173    assert( tr_isTimeval( &tv ) );
    175174    event_add( &dht_event, &tv );
    176175
     
    377376    /* Being slightly late is fine,
    378377       and has the added benefit of adding some jitter. */
    379     tv.tv_sec = tosleep;
    380     tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
    381     event_add(&dht_event, &tv);
     378    tr_timevalSet( &tv, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
     379    event_add( &dht_event, &tv );
    382380}
    383381
  • trunk/libtransmission/trevent.c

    r8662 r8681  
    304304    timer->inCallback = 0;
    305305
    306     if( more )
     306    if( !more )
     307        tr_timerFree( &timer );
     308    else {
     309        assert( tr_isTimeval( &timer->tv ) );
    307310        evtimer_add( &timer->event, &timer->tv );
    308     else
    309         tr_timerFree( &timer );
     311    }
    310312}
    311313
  • trunk/libtransmission/utils.c

    r8592 r8681  
    458458**/
    459459
     460tr_bool
     461tr_isTimeval( const struct timeval * tv )
     462{
     463    return tv && ( tv->tv_sec >= 0 )
     464              && ( tv->tv_usec >= 0 )
     465              && ( tv->tv_usec < 1000000 );
     466}
     467
    460468void
    461469tr_timevalMsec( uint64_t milliseconds, struct timeval * setme )
     
    465473    setme->tv_sec  = microseconds / 1000000;
    466474    setme->tv_usec = microseconds % 1000000;
    467 }
     475    assert( tr_isTimeval( setme ) );
     476}
     477
     478void
     479tr_timevalSet( struct timeval * setme, int seconds, int microseconds )
     480{
     481    setme->tv_sec = seconds;
     482    setme->tv_usec = microseconds;
     483    assert( tr_isTimeval( setme ) );
     484}
     485
     486
     487/**
     488***
     489**/
    468490
    469491uint8_t *
  • trunk/libtransmission/utils.h

    r8561 r8681  
    239239struct timeval;
    240240
    241 void tr_timevalMsec( uint64_t milliseconds, struct timeval   * setme );
     241tr_bool tr_isTimeval( const struct timeval * tv );
     242
     243void tr_timevalMsec( uint64_t milliseconds, struct timeval * setme );
     244
     245void tr_timevalSet( struct timeval * setme, int seconds, int microseconds );
    242246
    243247
Note: See TracChangeset for help on using the changeset viewer.