Changeset 7133


Ignore:
Timestamp:
Nov 21, 2008, 4:32:55 PM (14 years ago)
Author:
charles
Message:

(libT) define peer connections' sockets' so_sndbuf size in the tr_session struct.

Location:
trunk/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/net.c

    r7122 r7133  
    120120createSocket( int type )
    121121{
    122     const int fd = makeSocketNonBlocking( tr_fdSocketCreate( type ) );
    123 
    124     if( fd >= 0 ) {
    125         const int buffsize = 1500*3; /* 3x MTU for most ethernet/wireless */
    126         setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &buffsize, sizeof( buffsize ) );
    127     }
    128 
    129     return fd;
    130 }
    131 
    132 int
    133 tr_netOpenTCP( const struct in_addr * addr,
    134                tr_port_t              port )
     122    return makeSocketNonBlocking( tr_fdSocketCreate( type ) );
     123}
     124
     125static void
     126setSndBuf( tr_session * session, int fd )
     127{
     128    if( fd >= 0 )
     129    {
     130        const int sndbuf = session->so_sndbuf;
     131        setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof( sndbuf ) );
     132    }
     133}
     134
     135int
     136tr_netOpenTCP( tr_session            * session,
     137               const struct in_addr  * addr,
     138               tr_port_t               port )
    135139{
    136140    int                s;
     
    140144    if( ( s = createSocket( type ) ) < 0 )
    141145        return -1;
     146
     147    setSndBuf( session, s );
    142148
    143149    memset( &sock, 0, sizeof( sock ) );
     
    205211
    206212int
    207 tr_netAccept( int              b,
    208               struct in_addr * addr,
    209               tr_port_t *      port )
    210 {
    211     return makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
     213tr_netAccept( tr_session      * session,
     214              int               b,
     215              struct in_addr  * addr,
     216              tr_port_t       * port )
     217{
     218    int fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
     219    setSndBuf( session, fd );
     220    return fd;
    212221}
    213222
  • trunk/libtransmission/net.h

    r6924 r7133  
    5959struct in_addr;
    6060struct sockaddr_in;
     61struct tr_session;
    6162
    6263/***********************************************************************
     
    7071 * Sockets
    7172 **********************************************************************/
    72 int  tr_netOpenTCP( const struct in_addr * addr,
     73int  tr_netOpenTCP( struct tr_handle     * session,
     74                    const struct in_addr * addr,
    7375                    tr_port_t              port );
    7476
    7577int  tr_netBindTCP( int port );
    7678
    77 int  tr_netAccept( int    s,
    78                    struct in_addr *,
    79                           tr_port_t * );
     79int  tr_netAccept( struct tr_handle  * session,
     80                   int                 bound,
     81                   struct in_addr    * setme_addr,
     82                   tr_port_t         * setme_port );
    8083
    8184int  tr_netSetTOS( int s,
  • trunk/libtransmission/peer-io.c

    r7130 r7133  
    387387    assert( torrentHash );
    388388
    389     socket = tr_netOpenTCP( in_addr, port );
     389    socket = tr_netOpenTCP( session, in_addr, port );
    390390
    391391    return socket < 0
     
    493493        tr_netClose( io->socket );
    494494
    495     io->socket = tr_netOpenTCP( &io->in_addr, io->port );
     495    io->socket = tr_netOpenTCP( io->session, &io->in_addr, io->port );
    496496
    497497    if( io->socket >= 0 )
     
    716716***
    717717**/
    718 
    719 int
    720 tr_peerIoWantsBandwidth( const tr_peerIo * io,
    721                          tr_direction      direction )
    722 {
    723     assert( direction == TR_UP || direction == TR_DOWN );
    724 
    725     if( direction == TR_DOWN )
    726     {
    727         return TRUE; /* FIXME -- is there a good way to test for this? */
    728     }
    729     else
    730     {
    731         return EVBUFFER_LENGTH( EVBUFFER_OUTPUT( io->bufev ) )
    732                || EVBUFFER_LENGTH( io->output );
    733     }
    734 }
    735718
    736719void
  • trunk/libtransmission/peer-io.h

    r7125 r7133  
    129129**/
    130130
    131 int     tr_peerIoWantsBandwidth ( const tr_peerIo   * io,
    132                                   tr_direction        direction );
    133 
    134131void    tr_peerIoWrite          ( tr_peerIo         * io,
    135132                                  const void        * writeme,
  • trunk/libtransmission/port-forwarding.c

    r6795 r7133  
    4343    int                   publicPort;
    4444
    45     tr_handle *           h;
    46     tr_timer *            pulseTimer;
    47 
    48     tr_upnp *             upnp;
    49     tr_natpmp *           natpmp;
     45    tr_timer            * pulseTimer;
     46
     47    tr_upnp             * upnp;
     48    tr_natpmp           * natpmp;
     49    tr_session          * session;
    5050};
    5151
     
    146146            break;
    147147
    148         socket = tr_netAccept( s->bindSocket, &addr, &port );
     148        socket = tr_netAccept( s->session, s->bindSocket, &addr, &port );
    149149        if( socket < 0 )
    150150            break;
     
    152152        tr_deepLog( __FILE__, __LINE__, NULL,
    153153                   "New INCOMING connection %d (%s)",
    154                    socket, tr_peerIoAddrStr( &addr,
    155                                              port ) );
    156 
    157         tr_peerMgrAddIncoming( s->h->peerMgr, &addr, port, socket );
     154                   socket, tr_peerIoAddrStr( &addr, port ) );
     155
     156        tr_peerMgrAddIncoming( s->session->peerMgr, &addr, port, socket );
    158157    }
    159158}
     
    178177        tr_natpmpClose( shared->natpmp );
    179178        tr_upnpClose( shared->upnp );
    180         shared->h->shared = NULL;
     179        shared->session->shared = NULL;
    181180        tr_free( shared );
    182181        keepPulsing = 0;
     
    191190
    192191tr_shared *
    193 tr_sharedInit( tr_handle * h,
    194                int         isEnabled,
    195                int         publicPort )
     192tr_sharedInit( tr_session  * session,
     193               int           isEnabled,
     194               int           publicPort )
    196195{
    197196    tr_shared * s = tr_new0( tr_shared, 1 );
    198197
    199     s->h            = h;
     198    s->session      = session;
    200199    s->publicPort   = publicPort;
    201200    s->bindPort     = -1;
     
    203202    s->natpmp       = tr_natpmpInit( );
    204203    s->upnp         = tr_upnpInit( );
    205     s->pulseTimer   = tr_timerNew( h, sharedPulse, s, 1000 );
     204    s->pulseTimer   = tr_timerNew( session, sharedPulse, s, 1000 );
    206205    s->isEnabled    = isEnabled ? 1 : 0;
    207206    s->upnpStatus   = TR_PORT_UNMAPPED;
     
    225224    s->publicPort = port;
    226225
    227     while( ( tor = tr_torrentNext( s->h, tor ) ) )
     226    while( ( tor = tr_torrentNext( s->session, tor ) ) )
    228227        tr_torrentChangeMyPort( tor );
    229228}
  • trunk/libtransmission/session.c

    r7113 r7133  
    259259    h->rawSpeed[TR_PEER_TO_CLIENT] = tr_rcInit( );
    260260    h->rawSpeed[TR_CLIENT_TO_PEER] = tr_rcInit( );
     261    h->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */
    261262
    262263    if( configDir == NULL )
  • trunk/libtransmission/session.h

    r7069 r7133  
    106106    int                          metainfoLookupCount;
    107107
     108    /* the size of the output buffer for peer connections */
     109    int so_sndbuf;
     110
    108111    /* the rate at which pieces are being transferred between client and peer.
    109112     * protocol overhead is NOT included; this is only the piece data */
Note: See TracChangeset for help on using the changeset viewer.