1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

(trunk libT) #2035: Transmission causes wakeups by unnecessary polling

This commit is contained in:
Charles Kerr 2009-05-13 20:54:35 +00:00
parent 27bcce628c
commit 1fc7f10b6c
2 changed files with 40 additions and 16 deletions

View file

@ -53,7 +53,7 @@ enum
BANDWIDTH_PERIOD_MSEC = 500, BANDWIDTH_PERIOD_MSEC = 500,
/* how frequently to age out old piece request lists */ /* how frequently to age out old piece request lists */
REFILL_UPKEEP_PERIOD_MSEC = 10000, REFILL_UPKEEP_PERIOD_MSEC = ( 10 * 1000 ),
/* how frequently to decide which peers live and die */ /* how frequently to decide which peers live and die */
RECONNECT_PERIOD_MSEC = 500, RECONNECT_PERIOD_MSEC = 500,
@ -450,28 +450,33 @@ tr_peerMgr*
tr_peerMgrNew( tr_session * session ) tr_peerMgrNew( tr_session * session )
{ {
tr_peerMgr * m = tr_new0( tr_peerMgr, 1 ); tr_peerMgr * m = tr_new0( tr_peerMgr, 1 );
m->session = session; m->session = session;
m->incomingHandshakes = TR_PTR_ARRAY_INIT; m->incomingHandshakes = TR_PTR_ARRAY_INIT;
m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC );
m->rechokeTimer = tr_timerNew( session, rechokePulse, m, RECHOKE_PERIOD_MSEC );
m->reconnectTimer = tr_timerNew( session, reconnectPulse, m, RECONNECT_PERIOD_MSEC );
m->refillUpkeepTimer = tr_timerNew( session, refillUpkeep, m, REFILL_UPKEEP_PERIOD_MSEC );
rechokePulse( m );
return m; return m;
} }
static void
deleteTimers( struct tr_peerMgr * m )
{
if( m->bandwidthTimer )
tr_timerFree( &m->bandwidthTimer );
if( m->rechokeTimer == NULL )
tr_timerFree( &m->rechokeTimer );
if( m->reconnectTimer == NULL )
tr_timerFree( &m->reconnectTimer );
if( m->refillUpkeepTimer == NULL )
tr_timerFree( &m->refillUpkeepTimer );
}
void void
tr_peerMgrFree( tr_peerMgr * manager ) tr_peerMgrFree( tr_peerMgr * manager )
{ {
managerLock( manager ); managerLock( manager );
tr_timerFree( &manager->refillUpkeepTimer ); deleteTimers( manager );
tr_timerFree( &manager->reconnectTimer );
tr_timerFree( &manager->rechokeTimer );
tr_timerFree( &manager->bandwidthTimer );
/* free the handshakes. Abort invokes handshakeDoneCB(), which removes /* free the handshakes. Abort invokes handshakeDoneCB(), which removes
* the item from manager->handshakes, so this is a little roundabout... */ * the item from manager->handshakes, so this is a little roundabout... */
@ -1568,14 +1573,32 @@ tr_peerMgrGetPeers( tr_torrent * tor,
return peersReturning; return peersReturning;
} }
static void
ensureMgrTimersExist( struct tr_peerMgr * m )
{
tr_session * s = m->session;
if( m->bandwidthTimer == NULL )
m->bandwidthTimer = tr_timerNew( s, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC );
if( m->rechokeTimer == NULL )
m->rechokeTimer = tr_timerNew( s, rechokePulse, m, RECHOKE_PERIOD_MSEC );
if( m->reconnectTimer == NULL )
m->reconnectTimer = tr_timerNew( s, reconnectPulse, m, RECONNECT_PERIOD_MSEC );
if( m->refillUpkeepTimer == NULL )
m->refillUpkeepTimer = tr_timerNew( s, refillUpkeep, m, REFILL_UPKEEP_PERIOD_MSEC );
}
void void
tr_peerMgrStartTorrent( tr_torrent * tor ) tr_peerMgrStartTorrent( tr_torrent * tor )
{ {
Torrent * t = tor->torrentPeers; Torrent * t = tor->torrentPeers;
assert( t != NULL );
managerLock( t->manager ); managerLock( t->manager );
ensureMgrTimersExist( t->manager );
assert( t );
if( !t->isRunning ) if( !t->isRunning )
{ {
@ -1585,6 +1608,7 @@ tr_peerMgrStartTorrent( tr_torrent * tor )
refillSoon( t ); refillSoon( t );
} }
rechokePulse( t->manager );
managerUnlock( t->manager ); managerUnlock( t->manager );
} }

View file

@ -41,7 +41,7 @@ enum
HTTP_OK = 200, HTTP_OK = 200,
/* seconds between tracker pulses */ /* seconds between tracker pulses */
PULSE_INTERVAL_MSEC = 1000, PULSE_INTERVAL_MSEC = 1500,
/* unless the tracker says otherwise, rescrape this frequently */ /* unless the tracker says otherwise, rescrape this frequently */
DEFAULT_SCRAPE_INTERVAL_SEC = ( 60 * 15 ), DEFAULT_SCRAPE_INTERVAL_SEC = ( 60 * 15 ),