From 4792788d24783351a48da31add4d59b02623bbbc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 9 Nov 2007 16:10:48 +0000 Subject: [PATCH] move the gateway discovery from init() to start() so that tr_init() doesn't block. --- libtransmission/upnp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index 7b624841c..b59f40699 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -29,6 +29,7 @@ struct tr_upnp char lanaddr[16]; unsigned int isForwarding : 1; unsigned int isEnabled : 1; + unsigned int hasDiscovered : 1; }; /** @@ -39,13 +40,7 @@ tr_upnp* tr_upnpInit( void ) { tr_upnp * ret = tr_new0( tr_upnp, 1 ); - struct UPNPDev * devlist = upnpDiscover( 2000, NULL ); - if( UPNP_GetValidIGD( devlist, &ret->urls, &ret->data, ret->lanaddr, sizeof(ret->lanaddr))) { - tr_dbg( "Found Internet Gateway Device '%s'", ret->urls.controlURL ); - tr_dbg( "Local LAN IP Address is '%s'", ret->lanaddr ); - } ret->port = -1; - freeUPNPDevlist( devlist ); return ret; } @@ -53,7 +48,8 @@ void tr_upnpClose( tr_upnp * handle ) { tr_upnpStop( handle ); - FreeUPNPUrls( &handle->urls ); + if( handle->hasDiscovered ) + FreeUPNPUrls( &handle->urls ); tr_free( handle ); } @@ -64,6 +60,17 @@ tr_upnpClose( tr_upnp * handle ) void tr_upnpStart( tr_upnp * handle ) { + if( !handle->hasDiscovered ) + { + struct UPNPDev * devlist = upnpDiscover( 2000, NULL ); + if( UPNP_GetValidIGD( devlist, &handle->urls, &handle->data, handle->lanaddr, sizeof(handle->lanaddr))) { + tr_dbg( "Found Internet Gateway Device '%s'", handle->urls.controlURL ); + tr_dbg( "Local LAN IP Address is '%s'", handle->lanaddr ); + } + freeUPNPDevlist( devlist ); + handle->hasDiscovered = 1; + } + handle->isEnabled = 1; if( handle->port >= 0 )