Changeset 4102


Ignore:
Timestamp:
Dec 9, 2007, 12:28:34 AM (14 years ago)
Author:
charles
Message:

finish the `shared' update: bind & listen the incoming port.
better logging in network code.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r4092 r4102  
    157157    if( ( s = createSocket( type, 1 ) ) < 0 )
    158158    {
     159        tr_err( "Couldn't create socket of type %d", type );
    159160        return -1;
    160161    }
     
    177178        return -1;
    178179    }
    179 
     180     
     181    tr_inf( "Bound socket %d to port %d", port, s );
    180182    return s;
    181183}
  • trunk/libtransmission/shared.c

    r4092 r4102  
    9494
    9595static void
    96 checkForIncomingPeers( tr_shared * s )
    97 {
    98     for( ;; )
     96incomingPeersPulse( tr_shared * s )
     97{
     98    if( s->bindSocket >= 0 && ( s->bindPort != s->publicPort ) )
     99    {
     100        tr_inf( NATKEY "closing port %d", s->bindPort );
     101        tr_netClose( s->bindSocket );
     102        s->bindSocket = -1;
     103    }
     104
     105    if( s->bindPort != s->publicPort )
     106    {
     107        int socket;
     108        errno = 0;
     109        socket = tr_netBindTCP( s->publicPort );
     110        if( socket >= 0 ) {
     111            tr_inf( NATKEY "opened port %d to listen for incoming peer connections", s->publicPort );
     112            s->bindPort = s->publicPort;
     113            s->bindSocket = socket;
     114            listen( s->bindSocket, 5 );
     115        } else {
     116            tr_err( NATKEY "unable to open port %d to listen for incoming peer connections (errno is %d - %s)",
     117                    s->publicPort, errno, strerror(errno) );
     118            s->bindPort = -1;
     119            s->bindSocket = -1;
     120        }
     121    }
     122   
     123    for( ;; ) /* check for new incoming peer connections */   
    99124    {
    100125        int socket;
     
    123148    if( !shared->isShuttingDown )
    124149    {
    125         checkForIncomingPeers( shared );
     150        incomingPeersPulse( shared );
    126151    }
    127152    else if( ( shared->natStatus == TR_NAT_TRAVERSAL_ERROR ) || ( shared->natStatus == TR_NAT_TRAVERSAL_UNMAPPED ) )
Note: See TracChangeset for help on using the changeset viewer.