1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

Remove natpmp and upnp locks and rely on the shared lock.

This commit is contained in:
Josh Elsasser 2007-02-06 05:37:48 +00:00
parent f67ad8cf47
commit c4ad02aaf3
4 changed files with 6 additions and 49 deletions

View file

@ -82,7 +82,6 @@ struct tr_natpmp_s
struct in_addr dest;
int newport;
int mappedport;
tr_lock_t lock;
uint64_t renew;
tr_natpmp_req_t * req;
tr_natpmp_uptime_t uptime;
@ -149,16 +148,12 @@ tr_natpmpInit()
tr_dbg( "nat-pmp device is %s", addrstr );
}
tr_lockInit( &pmp->lock );
return pmp;
}
void
tr_natpmpStart( tr_natpmp_t * pmp )
{
tr_lockLock( &pmp->lock );
if( !pmp->active )
{
tr_inf( "starting nat-pmp" );
@ -168,15 +163,11 @@ tr_natpmpStart( tr_natpmp_t * pmp )
pmp->mcastfd = mcastsetup();
}
}
tr_lockUnlock( &pmp->lock );
}
void
tr_natpmpStop( tr_natpmp_t * pmp )
{
tr_lockLock( &pmp->lock );
if( pmp->active )
{
tr_inf( "stopping nat-pmp" );
@ -212,8 +203,6 @@ tr_natpmpStop( tr_natpmp_t * pmp )
break;
}
}
tr_lockUnlock( &pmp->lock );
}
int
@ -221,9 +210,6 @@ tr_natpmpStatus( tr_natpmp_t * pmp )
{
int ret;
tr_lockLock( &pmp->lock );
if( !pmp->active )
{
ret = ( PMP_STATE_DELETING == pmp->state ?
@ -259,18 +245,14 @@ tr_natpmpStatus( tr_natpmp_t * pmp )
}
}
tr_lockUnlock( &pmp->lock );
return ret;
}
void
tr_natpmpForwardPort( tr_natpmp_t * pmp, int port )
{
tr_lockLock( &pmp->lock );
tr_inf( "nat-pmp set port %i", port );
pmp->newport = port;
tr_lockUnlock( &pmp->lock );
}
void
@ -280,17 +262,13 @@ tr_natpmpClose( tr_natpmp_t * pmp )
tr_natpmpStop( pmp );
tr_natpmpPulse( pmp, NULL );
tr_lockLock( &pmp->lock );
killreq( &pmp->req );
tr_lockClose( &pmp->lock );
free( pmp );
}
void
tr_natpmpPulse( tr_natpmp_t * pmp, int * publicPort )
{
tr_lockLock( &pmp->lock );
if( 0 <= pmp->mcastfd )
{
mcastpulse( pmp );
@ -460,8 +438,6 @@ tr_natpmpPulse( tr_natpmp_t * pmp, int * publicPort )
{
*publicPort = -1;
}
tr_lockUnlock( &pmp->lock );
}
static int

View file

@ -48,7 +48,8 @@ void tr_sharedUnlock ( tr_shared_t * );
/***********************************************************************
* tr_sharedSetPort
***********************************************************************
* Changes the port for incoming connections
* Changes the port for incoming connections. tr_sharedGetPublicPort
* should be called with the shared lock held.
**********************************************************************/
void tr_sharedSetPort ( tr_shared_t *, int port );
int tr_sharedGetPublicPort ( tr_shared_t * s );
@ -56,7 +57,8 @@ int tr_sharedGetPublicPort ( tr_shared_t * s );
/***********************************************************************
* tr_sharedTraversalEnable, tr_sharedTraversalStatus
***********************************************************************
*
* Enables/disables and retrieves the status of NAT traversal. Should
* be called with the shared lock held.
**********************************************************************/
void tr_sharedTraversalEnable ( tr_shared_t *, int enable );
int tr_sharedTraversalStatus ( tr_shared_t * );

View file

@ -83,7 +83,9 @@ void tr_setBindPort( tr_handle_t * h, int port )
void tr_natTraversalEnable( tr_handle_t * h, int enable )
{
tr_sharedLock( h->shared );
tr_sharedTraversalEnable( h->shared, enable );
tr_sharedUnlock( h->shared );
}
tr_handle_status_t * tr_handleStatus( tr_handle_t * h )

View file

@ -90,7 +90,6 @@ struct tr_upnp_s
unsigned int active : 1;
unsigned int discovering : 1;
tr_upnp_device_t * devices;
tr_lock_t lock;
};
static int
@ -167,16 +166,12 @@ tr_upnpInit()
upnp->infd = -1;
upnp->outfd = -1;
tr_lockInit( &upnp->lock );
return upnp;
}
void
tr_upnpStart( tr_upnp_t * upnp )
{
tr_lockLock( &upnp->lock );
if( !upnp->active )
{
tr_inf( "starting upnp" );
@ -186,15 +181,11 @@ tr_upnpStart( tr_upnp_t * upnp )
upnp->lastdiscover = 0;
upnp->lastdelay = SSDP_FIRST_DELAY / 2;
}
tr_lockUnlock( &upnp->lock );
}
void
tr_upnpStop( tr_upnp_t * upnp )
{
tr_lockLock( &upnp->lock );
if( upnp->active )
{
tr_inf( "stopping upnp" );
@ -202,8 +193,6 @@ tr_upnpStop( tr_upnp_t * upnp )
killSock( &upnp->infd );
killSock( &upnp->outfd );
}
tr_lockUnlock( &upnp->lock );
}
int
@ -212,8 +201,6 @@ tr_upnpStatus( tr_upnp_t * upnp )
tr_upnp_device_t * ii;
int ret;
tr_lockLock( &upnp->lock );
if( !upnp->active )
{
ret = ( NULL == upnp->devices ?
@ -240,18 +227,14 @@ tr_upnpStatus( tr_upnp_t * upnp )
}
}
tr_lockUnlock( &upnp->lock );
return ret;
}
void
tr_upnpForwardPort( tr_upnp_t * upnp, int port )
{
tr_lockLock( &upnp->lock );
tr_dbg( "upnp port changed from %i to %i", upnp->port, port );
upnp->port = port;
tr_lockUnlock( &upnp->lock );
}
void
@ -259,13 +242,11 @@ tr_upnpClose( tr_upnp_t * upnp )
{
tr_upnpStop( upnp );
tr_lockLock( &upnp->lock );
while( NULL != upnp->devices )
{
deviceRemove( &upnp->devices );
}
tr_lockClose( &upnp->lock );
free( upnp );
}
@ -274,8 +255,6 @@ tr_upnpPulse( tr_upnp_t * upnp )
{
tr_upnp_device_t ** ii;
tr_lockLock( &upnp->lock );
if( upnp->active )
{
/* pulse on all known devices */
@ -321,8 +300,6 @@ tr_upnpPulse( tr_upnp_t * upnp )
}
}
}
tr_lockUnlock( &upnp->lock );
}
static int