Changeset 9704
- Timestamp:
- Dec 10, 2009, 5:52:46 AM (13 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-io.c
r9671 r9704 34 34 #include "peer-io.h" 35 35 #include "platform.h" /* MAX_STACK_ARRAY_SIZE */ 36 #include "trevent.h" 36 #include "trevent.h" /* tr_runInEventThread() */ 37 37 #include "utils.h" 38 38 -
trunk/libtransmission/peer-mgr.c
r9671 r9704 37 37 #include "stats.h" /* tr_statsAddUploaded, tr_statsAddDownloaded */ 38 38 #include "torrent.h" 39 #include "trevent.h"40 39 #include "utils.h" 41 40 #include "webseed.h" … … 48 47 /* how frequently to change which peers are choked */ 49 48 RECHOKE_PERIOD_MSEC = ( 10 * 1000 ), 50 51 /* minimum interval for refilling peers' request lists */52 REFILL_PERIOD_MSEC = 400,53 49 54 50 /* how frequently to reallocate bandwidth */ … … 189 185 struct tr_peerMgr 190 186 { 191 tr_session 192 tr_ptrArray 193 tr_timer* bandwidthTimer;194 tr_timer* rechokeTimer;195 tr_timer* reconnectTimer;196 tr_timer* refillUpkeepTimer;197 tr_timer* atomTimer;187 tr_session * session; 188 tr_ptrArray incomingHandshakes; /* tr_handshake */ 189 struct event * bandwidthTimer; 190 struct event * rechokeTimer; 191 struct event * reconnectTimer; 192 struct event * refillUpkeepTimer; 193 struct event * atomTimer; 198 194 }; 199 195 … … 469 465 470 466 static void 467 deleteTimer( struct event ** t ) 468 { 469 if( *t != NULL ) 470 { 471 evtimer_del( *t ); 472 tr_free( *t ); 473 *t = NULL; 474 } 475 } 476 477 static void 471 478 deleteTimers( struct tr_peerMgr * m ) 472 479 { 473 if( m->atomTimer ) 474 tr_timerFree( &m->atomTimer ); 475 476 if( m->bandwidthTimer ) 477 tr_timerFree( &m->bandwidthTimer ); 478 479 if( m->rechokeTimer ) 480 tr_timerFree( &m->rechokeTimer ); 481 482 if( m->reconnectTimer ) 483 tr_timerFree( &m->reconnectTimer ); 484 485 if( m->refillUpkeepTimer ) 486 tr_timerFree( &m->refillUpkeepTimer ); 480 deleteTimer( &m->atomTimer ); 481 deleteTimer( &m->bandwidthTimer ); 482 deleteTimer( &m->rechokeTimer ); 483 deleteTimer( &m->reconnectTimer ); 484 deleteTimer( &m->refillUpkeepTimer ); 487 485 } 488 486 … … 1011 1009 } 1012 1010 1011 static void 1012 renewTimer( struct event * timer, int msec ) 1013 { 1014 const int seconds = msec / 1000; 1015 const int usec = (msec%1000) * 1000; 1016 tr_timerAdd( timer, seconds, usec ); 1017 } 1018 1013 1019 /* cancel requests that are too old */ 1014 static int1015 refillUpkeep( void * vmgr )1020 static void 1021 refillUpkeep( int foo UNUSED, short bar UNUSED, void * vmgr ) 1016 1022 { 1017 1023 time_t now; … … 1064 1070 } 1065 1071 1072 renewTimer( mgr->refillUpkeepTimer, REFILL_UPKEEP_PERIOD_MSEC ); 1066 1073 managerUnlock( mgr ); 1067 return TRUE;1068 1074 } 1069 1075 … … 1841 1847 } 1842 1848 1843 static int atomPulse ( void * vmgr ); 1844 static int bandwidthPulse ( void * vmgr ); 1845 static int rechokePulse ( void * vmgr ); 1846 static int reconnectPulse ( void * vmgr ); 1849 static void atomPulse ( int, short, void * ); 1850 static void bandwidthPulse ( int, short, void * ); 1851 static void rechokePulse ( int, short, void * ); 1852 static void reconnectPulse ( int, short, void * ); 1853 1854 static struct event * 1855 createTimer( int msec, void (*callback)(int, short, void *), void * cbdata ) 1856 { 1857 struct event * timer = tr_new0( struct event, 1 ); 1858 evtimer_set( timer, callback, cbdata ); 1859 renewTimer( timer, msec ); 1860 return timer; 1861 } 1847 1862 1848 1863 static void 1849 1864 ensureMgrTimersExist( struct tr_peerMgr * m ) 1850 1865 { 1851 tr_session * s = m->session;1852 1853 1866 if( m->atomTimer == NULL ) 1854 m->atomTimer = tr_timerNew( s, atomPulse, m, ATOM_PERIOD_MSEC);1867 m->atomTimer = createTimer( ATOM_PERIOD_MSEC, atomPulse, m ); 1855 1868 1856 1869 if( m->bandwidthTimer == NULL ) 1857 m->bandwidthTimer = tr_timerNew( s, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC);1870 m->bandwidthTimer = createTimer( BANDWIDTH_PERIOD_MSEC, bandwidthPulse, m ); 1858 1871 1859 1872 if( m->rechokeTimer == NULL ) 1860 m->rechokeTimer = tr_timerNew( s, rechokePulse, m, RECHOKE_PERIOD_MSEC);1873 m->rechokeTimer = createTimer( RECHOKE_PERIOD_MSEC, rechokePulse, m ); 1861 1874 1862 1875 if( m->reconnectTimer == NULL ) 1863 m->reconnectTimer = tr_timerNew( s, reconnectPulse, m, RECONNECT_PERIOD_MSEC);1876 m->reconnectTimer = createTimer( RECONNECT_PERIOD_MSEC, reconnectPulse, m ); 1864 1877 1865 1878 if( m->refillUpkeepTimer == NULL ) 1866 m->refillUpkeepTimer = tr_timerNew( s, refillUpkeep, m, REFILL_UPKEEP_PERIOD_MSEC);1879 m->refillUpkeepTimer = createTimer( REFILL_UPKEEP_PERIOD_MSEC, refillUpkeep, m ); 1867 1880 } 1868 1881 … … 1878 1891 t->isRunning = TRUE; 1879 1892 1880 rechokePulse( t->manager );1893 rechokePulse( 0, 0, t->manager ); 1881 1894 managerUnlock( t->manager ); 1882 1895 } … … 2321 2334 } 2322 2335 2323 static int2324 rechokePulse( void * vmgr )2336 static void 2337 rechokePulse( int foo UNUSED, short bar UNUSED, void * vmgr ) 2325 2338 { 2326 2339 uint64_t now; … … 2334 2347 rechokeTorrent( tor->torrentPeers, now ); 2335 2348 2349 renewTimer( mgr->rechokeTimer, RECHOKE_PERIOD_MSEC ); 2336 2350 managerUnlock( mgr ); 2337 return TRUE;2338 2351 } 2339 2352 … … 2865 2878 2866 2879 2867 static int2868 reconnectPulse( void * vmgr )2880 static void 2881 reconnectPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) 2869 2882 { 2870 2883 tr_torrent * tor; … … 2889 2902 reconnectTorrent( tor->torrentPeers ); 2890 2903 2904 renewTimer( mgr->reconnectTimer, RECONNECT_PERIOD_MSEC ); 2891 2905 managerUnlock( mgr ); 2892 return TRUE;2893 2906 } 2894 2907 … … 2917 2930 } 2918 2931 2919 static int2920 bandwidthPulse( void * vmgr )2932 static void 2933 bandwidthPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) 2921 2934 { 2922 2935 tr_torrent * tor = NULL; … … 2954 2967 tr_torrentStop( tor ); 2955 2968 2969 renewTimer( mgr->bandwidthTimer, BANDWIDTH_PERIOD_MSEC ); 2956 2970 managerUnlock( mgr ); 2957 return TRUE;2958 2971 } 2959 2972 … … 3014 3027 } 3015 3028 3016 static int3017 atomPulse( void * vmgr )3029 static void 3030 atomPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) 3018 3031 { 3019 3032 tr_torrent * tor = NULL; … … 3073 3086 } 3074 3087 3088 renewTimer( mgr->atomTimer, ATOM_PERIOD_MSEC ); 3075 3089 managerUnlock( mgr ); 3076 return TRUE; 3077 } 3090 } -
trunk/libtransmission/port-forwarding.c
r9671 r9704 25 25 #include "session.h" 26 26 #include "torrent.h" 27 #include "trevent.h"28 27 #include "upnp.h" 29 28 #include "utils.h" -
trunk/libtransmission/torrent.c
r9691 r9704 41 41 #include "torrent.h" 42 42 #include "torrent-magnet.h" 43 #include "trevent.h" 43 #include "trevent.h" /* tr_runInEventThread() */ 44 44 #include "utils.h" 45 45 #include "verify.h" -
trunk/libtransmission/trevent.c
r9671 r9704 133 133 tr_event_handle; 134 134 135 typedef int timer_func ( void* );136 137 struct tr_timer138 {139 tr_bool inCallback;140 timer_func * func;141 void * user_data;142 struct tr_event_handle * eh;143 struct timeval tv;144 struct event event;145 };146 147 135 struct tr_run_data 148 136 { … … 281 269 282 270 tr_bool 283 tr_amInEventThread( tr_session * session )271 tr_amInEventThread( const tr_session * session ) 284 272 { 285 273 assert( tr_isSession( session ) ); … … 292 280 *** 293 281 **/ 294 295 static void296 timerCallback( int fd UNUSED,297 short event UNUSED,298 void * vtimer )299 {300 int more;301 struct tr_timer * timer = vtimer;302 303 timer->inCallback = 1;304 more = ( *timer->func )( timer->user_data );305 timer->inCallback = 0;306 307 if( !more )308 tr_timerFree( &timer );309 else {310 assert( tr_isTimeval( &timer->tv ) );311 evtimer_add( &timer->event, &timer->tv );312 }313 }314 315 void316 tr_timerFree( tr_timer ** ptimer )317 {318 tr_timer * timer;319 320 /* zero out the argument passed in */321 assert( ptimer );322 timer = *ptimer;323 *ptimer = NULL;324 325 /* destroy the timer directly or via the command queue */326 if( timer && !timer->inCallback )327 {328 assert( tr_amInEventThread( timer->eh->session ) );329 event_del( &timer->event );330 tr_free( timer );331 }332 }333 334 tr_timer*335 tr_timerNew( tr_session * session,336 timer_func func,337 void * user_data,338 uint64_t interval_milliseconds )339 {340 tr_timer * timer;341 342 assert( tr_amInEventThread( session ) );343 344 timer = tr_new0( tr_timer, 1 );345 timer->func = func;346 timer->user_data = user_data;347 timer->eh = session->events;348 349 tr_timevalMsec( interval_milliseconds, &timer->tv );350 evtimer_set( &timer->event, timerCallback, timer );351 evtimer_add( &timer->event, &timer->tv );352 353 return timer;354 }355 282 356 283 void -
trunk/libtransmission/trevent.h
r9671 r9704 28 28 void tr_eventClose( tr_session * ); 29 29 30 tr_bool tr_amInEventThread( const tr_session * ); 31 32 void tr_runInEventThread( tr_session *, void func( void* ), void * user_data ); 33 30 34 struct event_base * tr_eventGetBase( tr_session * ); 31 35 32 33 typedef struct tr_timer tr_timer;34 35 /**36 * Calls timer_func(user_data) after the specified interval.37 * The timer is freed if timer_func returns zero.38 * Otherwise, it's called again after the same interval.39 */40 tr_timer* tr_timerNew( tr_session * handle,41 int func( void * user_data ),42 void * user_data,43 uint64_t timeout_milliseconds );44 45 /**46 * Frees a timer and sets the timer pointer to NULL.47 */48 void tr_timerFree( tr_timer ** timer );49 50 51 tr_bool tr_amInEventThread( tr_session * );52 53 void tr_runInEventThread( tr_session * session,54 void func( void* ),55 void * user_data );56 57 36 #endif -
trunk/libtransmission/web.c
r9671 r9704 23 23 #include "net.h" /* socklen_t */ 24 24 #include "session.h" 25 #include "trevent.h" 25 #include "trevent.h" /* tr_runInEventThread() */ 26 26 #include "utils.h" 27 27 #include "version.h"
Note: See TracChangeset
for help on using the changeset viewer.