finish the `shared' update: bind & listen the incoming port.

better logging in network code.
This commit is contained in:
Charles Kerr 2007-12-09 00:28:34 +00:00
parent d4cf34c0c1
commit 67a86a2274
2 changed files with 31 additions and 4 deletions

View File

@ -156,6 +156,7 @@ tr_netBind( int port, int type )
if( ( s = createSocket( type, 1 ) ) < 0 )
{
tr_err( "Couldn't create socket of type %d", type );
return -1;
}
@ -176,7 +177,8 @@ tr_netBind( int port, int type )
tr_netClose( s );
return -1;
}
tr_inf( "Bound socket %d to port %d", port, s );
return s;
}

View File

@ -93,9 +93,34 @@ natPulse( tr_shared * s )
}
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;
uint16_t port;
@ -122,7 +147,7 @@ sharedPulse( void * vshared )
if( !shared->isShuttingDown )
{
checkForIncomingPeers( shared );
incomingPeersPulse( shared );
}
else if( ( shared->natStatus == TR_NAT_TRAVERSAL_ERROR ) || ( shared->natStatus == TR_NAT_TRAVERSAL_UNMAPPED ) )
{