1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

move the gateway discovery from init() to start() so that tr_init() doesn't block.

This commit is contained in:
Charles Kerr 2007-11-09 16:10:48 +00:00
parent e168cf3f69
commit 4792788d24

View file

@ -29,6 +29,7 @@ struct tr_upnp
char lanaddr[16]; char lanaddr[16];
unsigned int isForwarding : 1; unsigned int isForwarding : 1;
unsigned int isEnabled : 1; unsigned int isEnabled : 1;
unsigned int hasDiscovered : 1;
}; };
/** /**
@ -39,13 +40,7 @@ tr_upnp*
tr_upnpInit( void ) tr_upnpInit( void )
{ {
tr_upnp * ret = tr_new0( tr_upnp, 1 ); 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; ret->port = -1;
freeUPNPDevlist( devlist );
return ret; return ret;
} }
@ -53,6 +48,7 @@ void
tr_upnpClose( tr_upnp * handle ) tr_upnpClose( tr_upnp * handle )
{ {
tr_upnpStop( handle ); tr_upnpStop( handle );
if( handle->hasDiscovered )
FreeUPNPUrls( &handle->urls ); FreeUPNPUrls( &handle->urls );
tr_free( handle ); tr_free( handle );
} }
@ -64,6 +60,17 @@ tr_upnpClose( tr_upnp * handle )
void void
tr_upnpStart( tr_upnp * handle ) 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; handle->isEnabled = 1;
if( handle->port >= 0 ) if( handle->port >= 0 )