Changeset 3770


Ignore:
Timestamp:
Nov 9, 2007, 4:10:48 PM (15 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/upnp.c

    r3743 r3770  
    3030    unsigned int isForwarding : 1;
    3131    unsigned int isEnabled : 1;
     32    unsigned int hasDiscovered : 1;
    3233};
    3334
     
    4041{
    4142    tr_upnp * ret = tr_new0( tr_upnp, 1 );
    42     struct UPNPDev * devlist = upnpDiscover( 2000, NULL );
    43     if( UPNP_GetValidIGD( devlist, &ret->urls, &ret->data, ret->lanaddr, sizeof(ret->lanaddr))) {
    44         tr_dbg( "Found Internet Gateway Device '%s'", ret->urls.controlURL );
    45         tr_dbg( "Local LAN IP Address is '%s'", ret->lanaddr );
    46     }
    4743    ret->port = -1;
    48     freeUPNPDevlist( devlist );
    4944    return ret;
    5045}
     
    5449{
    5550    tr_upnpStop( handle );
    56     FreeUPNPUrls( &handle->urls );
     51    if( handle->hasDiscovered )
     52        FreeUPNPUrls( &handle->urls );
    5753    tr_free( handle );
    5854}
     
    6561tr_upnpStart( tr_upnp * handle )
    6662{
     63    if( !handle->hasDiscovered )
     64    {
     65        struct UPNPDev * devlist = upnpDiscover( 2000, NULL );
     66        if( UPNP_GetValidIGD( devlist, &handle->urls, &handle->data, handle->lanaddr, sizeof(handle->lanaddr))) {
     67            tr_dbg( "Found Internet Gateway Device '%s'", handle->urls.controlURL );
     68            tr_dbg( "Local LAN IP Address is '%s'", handle->lanaddr );
     69        }
     70        freeUPNPDevlist( devlist );
     71        handle->hasDiscovered = 1;
     72    }
     73
    6774    handle->isEnabled = 1;
    6875
Note: See TracChangeset for help on using the changeset viewer.