diff options
Diffstat (limited to 'trackerlogic.c')
-rw-r--r-- | trackerlogic.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/trackerlogic.c b/trackerlogic.c index 249a2a0..8ebaa46 100644 --- a/trackerlogic.c +++ b/trackerlogic.c | |||
@@ -337,6 +337,23 @@ size_t remove_peer_from_torrent( ot_hash hash, ot_peer *peer, char *reply, PROTO | |||
337 | return reply_size; | 337 | return reply_size; |
338 | } | 338 | } |
339 | 339 | ||
340 | void iterate_all_torrents( int (*for_each)( ot_torrent* torrent, uintptr_t data ), uintptr_t data ) { | ||
341 | int bucket; | ||
342 | size_t j; | ||
343 | |||
344 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | ||
345 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | ||
346 | ot_torrent *torrents = (ot_torrent*)(torrents_list->data); | ||
347 | |||
348 | for( j=0; j<torrents_list->size; ++j ) | ||
349 | if( for_each( torrents + j, data ) ) | ||
350 | break; | ||
351 | |||
352 | mutex_bucket_unlock( bucket, 0 ); | ||
353 | if( !g_opentracker_running ) return; | ||
354 | } | ||
355 | } | ||
356 | |||
340 | void exerr( char * message ) { | 357 | void exerr( char * message ) { |
341 | fprintf( stderr, "%s\n", message ); | 358 | fprintf( stderr, "%s\n", message ); |
342 | exit( 111 ); | 359 | exit( 111 ); |
@@ -358,7 +375,7 @@ void trackerlogic_init( ) { | |||
358 | void trackerlogic_deinit( void ) { | 375 | void trackerlogic_deinit( void ) { |
359 | int bucket, delta_torrentcount = 0; | 376 | int bucket, delta_torrentcount = 0; |
360 | size_t j; | 377 | size_t j; |
361 | 378 | ||
362 | /* Free all torrents... */ | 379 | /* Free all torrents... */ |
363 | for(bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | 380 | for(bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { |
364 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 381 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |