better cleanup on shutdown. don't crash when the torrent doesn't support scrape. (Gimp :)

This commit is contained in:
Charles Kerr 2007-08-20 23:37:08 +00:00
parent 64faed5c47
commit 624257c995
2 changed files with 23 additions and 12 deletions

View File

@ -532,8 +532,19 @@ getCurrentAddress( const Tracker * t )
assert( t->addresses != NULL );
assert( t->addressIndex >= 0 );
assert( t->addressIndex < t->addressCount );
return &t->addresses[t->addressIndex];
}
static int
trackerSupportsScrape( const Tracker * t )
{
const tr_tracker_info_t * info = getCurrentAddress( t );
return ( info != NULL )
&& ( info->scrape != NULL )
&& ( info->scrape[0] != '\0' );
}
static void
addCommonHeaders( const Tracker * t,
@ -559,8 +570,10 @@ static int
onTorrentScrapeNow( void * vtor )
{
Torrent * tor = (Torrent *) vtor;
tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare );
tr_trackerScrapeSoon( tor->tracker );
if( trackerSupportsScrape( tor->tracker ) ) {
tr_ptrArrayInsertSorted( tor->tracker->scrapeQueue, tor, torrentCompare );
tr_trackerScrapeSoon( tor->tracker );
}
tor->scrapeTag = NULL;
return FALSE;
}
@ -678,10 +691,11 @@ static int
onTrackerScrapeNow( void * vt )
{
Tracker * t = (Tracker*) vt;
const tr_tracker_info_t * address = getCurrentAddress( t );
assert( tr_ptrArrayEmpty( t->scraping ) );
if( !tr_ptrArrayEmpty( t->scrapeQueue ) )
if( trackerSupportsScrape( t ) && !tr_ptrArrayEmpty( t->scrapeQueue ) )
{
int i, n, len, addr_len, ask_n;
char *march, *uri;
@ -689,7 +703,6 @@ onTrackerScrapeNow( void * vt )
(Torrent**) tr_ptrArrayPeek( t->scrapeQueue, &n );
struct evhttp_connection *evcon = NULL;
struct evhttp_request *req = NULL;
const tr_tracker_info_t * address = getCurrentAddress( t );
ask_n = n;
if( ask_n > t->multiscrapeMax )

View File

@ -12,7 +12,6 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -35,6 +34,7 @@
/* #define DEBUG */
#ifdef DEBUG
#include <stdio.h>
#undef tr_dbg
#define tr_dbg( a, b... ) fprintf(stderr, a "\n", ##b )
#endif
@ -46,9 +46,9 @@
typedef struct tr_event_handle_s
{
int fds[2];
int isShuttingDown;
tr_lock_t * lock;
tr_handle_t * h;
struct event_base * base;
struct event pipeEvent;
}
tr_event_handle_t;
@ -138,20 +138,18 @@ libeventThreadFunc( void * veh )
tr_event_handle_t * eh = (tr_event_handle_t *) veh;
tr_dbg( "Starting libevent thread" );
event_init( );
eh->base = event_init( );
event_set_log_callback( logFunc );
/* listen to the pipe's read fd */
event_set( &eh->pipeEvent, eh->fds[0], EV_READ|EV_PERSIST, readFromPipe, NULL );
event_add( &eh->pipeEvent, NULL );
while( !eh->isShuttingDown ) {
event_dispatch( );
tr_wait( 50 ); /* 1/20th of a second */
}
event_dispatch( );
event_del( &eh->pipeEvent );
tr_lockFree( eh->lock );
event_base_free( eh->base );
tr_free( eh );
tr_dbg( "Closing libevent thread" );
@ -175,7 +173,7 @@ tr_eventClose( tr_handle_t * handle )
{
tr_event_handle_t * eh = handle->events;
eh->isShuttingDown = TRUE;
event_base_loopexit( eh->base, NULL );
}
void