mirror of
https://github.com/transmission/transmission
synced 2025-03-12 07:03:44 +00:00
(trunk libT) possible fix for #2078: Assertion failed: (tv->tv_usec >= 0)
This commit is contained in:
parent
8f1d036fa3
commit
a2b9fcc592
6 changed files with 45 additions and 20 deletions
|
@ -108,21 +108,21 @@ onTimer( int fd UNUSED, short what UNUSED, void * vshared )
|
|||
/* if we're mapped, everything is fine... check back in 20 minutes
|
||||
* to renew the port forwarding if it's expired */
|
||||
s->doPortCheck = TRUE;
|
||||
interval.tv_sec = 60*20;
|
||||
tr_timevalSet( &interval, 60*20, 0 );
|
||||
break;
|
||||
|
||||
case TR_PORT_ERROR:
|
||||
/* some kind of an error. wait 60 seconds and retry */
|
||||
interval.tv_sec = 60;
|
||||
tr_timevalSet( &interval, 60, 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
/* in progress. pulse frequently. */
|
||||
interval.tv_sec = 0;
|
||||
interval.tv_usec = 333000;
|
||||
tr_timevalSet( &interval, 0, 333000 );
|
||||
break;
|
||||
}
|
||||
|
||||
assert( tr_isTimeval( &interval ) );
|
||||
evtimer_add( s->timer, &interval );
|
||||
}
|
||||
|
||||
|
@ -143,10 +143,10 @@ tr_sharedInit( tr_session * session, tr_bool isEnabled )
|
|||
if( isEnabled )
|
||||
{
|
||||
struct timeval timeval;
|
||||
timeval.tv_sec = 0;
|
||||
timeval.tv_usec = 333000;
|
||||
|
||||
s->timer = tr_new0( struct event, 1 );
|
||||
evtimer_set( s->timer, onTimer, s );
|
||||
tr_timevalSet( &timeval, 0, 333000 );
|
||||
evtimer_add( s->timer, &timeval );
|
||||
}
|
||||
|
||||
|
|
|
@ -1068,8 +1068,7 @@ setAltTimer( tr_session * session )
|
|||
assert( session->altTimer != NULL );
|
||||
|
||||
tr_localtime_r( &now, &tm );
|
||||
tv.tv_sec = 60 - tm.tm_sec;
|
||||
tv.tv_usec = 0;
|
||||
tr_timevalSet( &tv, 60-tm.tm_sec, 0 );
|
||||
evtimer_add( session->altTimer, &tv );
|
||||
}
|
||||
|
||||
|
|
|
@ -91,9 +91,8 @@ dht_bootstrap(void *closure)
|
|||
if(status == TR_DHT_STOPPED || status >= TR_DHT_FIREWALLED)
|
||||
break;
|
||||
tr_dhtAddNode(cl->session, &addr, port, 1);
|
||||
tv.tv_sec = 2 + tr_cryptoWeakRandInt( 5 );
|
||||
tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
tr_timevalSet( &tv, 2 + tr_cryptoWeakRandInt( 5 ), tr_cryptoWeakRandInt( 1000000 ) );
|
||||
select( 0, NULL, NULL, NULL, &tv );
|
||||
}
|
||||
tr_free( cl->nodes );
|
||||
tr_free( closure );
|
||||
|
@ -169,9 +168,9 @@ tr_dhtInit(tr_session *ss)
|
|||
tr_threadNew( dht_bootstrap, cl );
|
||||
}
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
|
||||
tr_timevalSet( &tv, 0, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
event_set( &dht_event, dht_socket, EV_READ, event_callback, NULL );
|
||||
assert( tr_isTimeval( &tv ) );
|
||||
event_add( &dht_event, &tv );
|
||||
|
||||
return 1;
|
||||
|
@ -376,9 +375,8 @@ event_callback(int s, short type, void *ignore UNUSED )
|
|||
|
||||
/* Being slightly late is fine,
|
||||
and has the added benefit of adding some jitter. */
|
||||
tv.tv_sec = tosleep;
|
||||
tv.tv_usec = tr_cryptoWeakRandInt( 1000000 );
|
||||
event_add(&dht_event, &tv);
|
||||
tr_timevalSet( &tv, tosleep, tr_cryptoWeakRandInt( 1000000 ) );
|
||||
event_add( &dht_event, &tv );
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -303,10 +303,12 @@ timerCallback( int fd UNUSED,
|
|||
more = ( *timer->func )( timer->user_data );
|
||||
timer->inCallback = 0;
|
||||
|
||||
if( more )
|
||||
evtimer_add( &timer->event, &timer->tv );
|
||||
else
|
||||
if( !more )
|
||||
tr_timerFree( &timer );
|
||||
else {
|
||||
assert( tr_isTimeval( &timer->tv ) );
|
||||
evtimer_add( &timer->event, &timer->tv );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -457,6 +457,14 @@ tr_strip_positional_args( const char* str )
|
|||
***
|
||||
**/
|
||||
|
||||
tr_bool
|
||||
tr_isTimeval( const struct timeval * tv )
|
||||
{
|
||||
return tv && ( tv->tv_sec >= 0 )
|
||||
&& ( tv->tv_usec >= 0 )
|
||||
&& ( tv->tv_usec < 1000000 );
|
||||
}
|
||||
|
||||
void
|
||||
tr_timevalMsec( uint64_t milliseconds, struct timeval * setme )
|
||||
{
|
||||
|
@ -464,8 +472,22 @@ tr_timevalMsec( uint64_t milliseconds, struct timeval * setme )
|
|||
assert( setme != NULL );
|
||||
setme->tv_sec = microseconds / 1000000;
|
||||
setme->tv_usec = microseconds % 1000000;
|
||||
assert( tr_isTimeval( setme ) );
|
||||
}
|
||||
|
||||
void
|
||||
tr_timevalSet( struct timeval * setme, int seconds, int microseconds )
|
||||
{
|
||||
setme->tv_sec = seconds;
|
||||
setme->tv_usec = microseconds;
|
||||
assert( tr_isTimeval( setme ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
|
||||
uint8_t *
|
||||
tr_loadFile( const char * path,
|
||||
size_t * size )
|
||||
|
|
|
@ -238,7 +238,11 @@ char* tr_buildPath( const char * first_element, ... ) TR_GNUC_NULL_TERMINATED
|
|||
|
||||
struct timeval;
|
||||
|
||||
void tr_timevalMsec( uint64_t milliseconds, struct timeval * setme );
|
||||
tr_bool tr_isTimeval( const struct timeval * tv );
|
||||
|
||||
void tr_timevalMsec( uint64_t milliseconds, struct timeval * setme );
|
||||
|
||||
void tr_timevalSet( struct timeval * setme, int seconds, int microseconds );
|
||||
|
||||
|
||||
/** @brief return the current date in milliseconds */
|
||||
|
|
Loading…
Add table
Reference in a new issue