finish the `shared' update: bind & listen the incoming port.
better logging in network code.
This commit is contained in:
parent
d4cf34c0c1
commit
67a86a2274
|
@ -156,6 +156,7 @@ tr_netBind( int port, int type )
|
||||||
|
|
||||||
if( ( s = createSocket( type, 1 ) ) < 0 )
|
if( ( s = createSocket( type, 1 ) ) < 0 )
|
||||||
{
|
{
|
||||||
|
tr_err( "Couldn't create socket of type %d", type );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +178,7 @@ tr_netBind( int port, int type )
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tr_inf( "Bound socket %d to port %d", port, s );
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,34 @@ natPulse( tr_shared * s )
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
checkForIncomingPeers( tr_shared * s )
|
incomingPeersPulse( tr_shared * s )
|
||||||
{
|
{
|
||||||
for( ;; )
|
if( s->bindSocket >= 0 && ( s->bindPort != s->publicPort ) )
|
||||||
|
{
|
||||||
|
tr_inf( NATKEY "closing port %d", s->bindPort );
|
||||||
|
tr_netClose( s->bindSocket );
|
||||||
|
s->bindSocket = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( s->bindPort != s->publicPort )
|
||||||
|
{
|
||||||
|
int socket;
|
||||||
|
errno = 0;
|
||||||
|
socket = tr_netBindTCP( s->publicPort );
|
||||||
|
if( socket >= 0 ) {
|
||||||
|
tr_inf( NATKEY "opened port %d to listen for incoming peer connections", s->publicPort );
|
||||||
|
s->bindPort = s->publicPort;
|
||||||
|
s->bindSocket = socket;
|
||||||
|
listen( s->bindSocket, 5 );
|
||||||
|
} else {
|
||||||
|
tr_err( NATKEY "unable to open port %d to listen for incoming peer connections (errno is %d - %s)",
|
||||||
|
s->publicPort, errno, strerror(errno) );
|
||||||
|
s->bindPort = -1;
|
||||||
|
s->bindSocket = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( ;; ) /* check for new incoming peer connections */
|
||||||
{
|
{
|
||||||
int socket;
|
int socket;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
@ -122,7 +147,7 @@ sharedPulse( void * vshared )
|
||||||
|
|
||||||
if( !shared->isShuttingDown )
|
if( !shared->isShuttingDown )
|
||||||
{
|
{
|
||||||
checkForIncomingPeers( shared );
|
incomingPeersPulse( shared );
|
||||||
}
|
}
|
||||||
else if( ( shared->natStatus == TR_NAT_TRAVERSAL_ERROR ) || ( shared->natStatus == TR_NAT_TRAVERSAL_UNMAPPED ) )
|
else if( ( shared->natStatus == TR_NAT_TRAVERSAL_ERROR ) || ( shared->natStatus == TR_NAT_TRAVERSAL_UNMAPPED ) )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue