mirror of
https://github.com/transmission/transmission
synced 2025-03-13 07:33:02 +00:00
(libT) define peer connections' sockets' so_sndbuf size in the tr_session struct.
This commit is contained in:
parent
d7b3024dbc
commit
853a67fbfc
7 changed files with 48 additions and 53 deletions
|
@ -119,19 +119,23 @@ makeSocketNonBlocking( int fd )
|
|||
static int
|
||||
createSocket( int type )
|
||||
{
|
||||
const int fd = makeSocketNonBlocking( tr_fdSocketCreate( type ) );
|
||||
return makeSocketNonBlocking( tr_fdSocketCreate( type ) );
|
||||
}
|
||||
|
||||
if( fd >= 0 ) {
|
||||
const int buffsize = 1500*3; /* 3x MTU for most ethernet/wireless */
|
||||
setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &buffsize, sizeof( buffsize ) );
|
||||
static void
|
||||
setSndBuf( tr_session * session, int fd )
|
||||
{
|
||||
if( fd >= 0 )
|
||||
{
|
||||
const int sndbuf = session->so_sndbuf;
|
||||
setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof( sndbuf ) );
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
tr_netOpenTCP( const struct in_addr * addr,
|
||||
tr_port_t port )
|
||||
tr_netOpenTCP( tr_session * session,
|
||||
const struct in_addr * addr,
|
||||
tr_port_t port )
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_in sock;
|
||||
|
@ -140,6 +144,8 @@ tr_netOpenTCP( const struct in_addr * addr,
|
|||
if( ( s = createSocket( type ) ) < 0 )
|
||||
return -1;
|
||||
|
||||
setSndBuf( session, s );
|
||||
|
||||
memset( &sock, 0, sizeof( sock ) );
|
||||
sock.sin_family = AF_INET;
|
||||
sock.sin_addr.s_addr = addr->s_addr;
|
||||
|
@ -204,11 +210,14 @@ tr_netBindTCP( int port )
|
|||
}
|
||||
|
||||
int
|
||||
tr_netAccept( int b,
|
||||
struct in_addr * addr,
|
||||
tr_port_t * port )
|
||||
tr_netAccept( tr_session * session,
|
||||
int b,
|
||||
struct in_addr * addr,
|
||||
tr_port_t * port )
|
||||
{
|
||||
return makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
|
||||
int fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) );
|
||||
setSndBuf( session, fd );
|
||||
return fd;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
|
||||
struct in_addr;
|
||||
struct sockaddr_in;
|
||||
struct tr_session;
|
||||
|
||||
/***********************************************************************
|
||||
* DNS resolution
|
||||
|
@ -69,14 +70,16 @@ int tr_netResolve( const char *,
|
|||
/***********************************************************************
|
||||
* Sockets
|
||||
**********************************************************************/
|
||||
int tr_netOpenTCP( const struct in_addr * addr,
|
||||
int tr_netOpenTCP( struct tr_handle * session,
|
||||
const struct in_addr * addr,
|
||||
tr_port_t port );
|
||||
|
||||
int tr_netBindTCP( int port );
|
||||
|
||||
int tr_netAccept( int s,
|
||||
struct in_addr *,
|
||||
tr_port_t * );
|
||||
int tr_netAccept( struct tr_handle * session,
|
||||
int bound,
|
||||
struct in_addr * setme_addr,
|
||||
tr_port_t * setme_port );
|
||||
|
||||
int tr_netSetTOS( int s,
|
||||
int tos );
|
||||
|
|
|
@ -386,7 +386,7 @@ tr_peerIoNewOutgoing( tr_session * session,
|
|||
assert( port >= 0 );
|
||||
assert( torrentHash );
|
||||
|
||||
socket = tr_netOpenTCP( in_addr, port );
|
||||
socket = tr_netOpenTCP( session, in_addr, port );
|
||||
|
||||
return socket < 0
|
||||
? NULL
|
||||
|
@ -492,7 +492,7 @@ tr_peerIoReconnect( tr_peerIo * io )
|
|||
if( io->socket >= 0 )
|
||||
tr_netClose( io->socket );
|
||||
|
||||
io->socket = tr_netOpenTCP( &io->in_addr, io->port );
|
||||
io->socket = tr_netOpenTCP( io->session, &io->in_addr, io->port );
|
||||
|
||||
if( io->socket >= 0 )
|
||||
{
|
||||
|
@ -716,23 +716,6 @@ tr_peerIoIsEncrypted( const tr_peerIo * io )
|
|||
***
|
||||
**/
|
||||
|
||||
int
|
||||
tr_peerIoWantsBandwidth( const tr_peerIo * io,
|
||||
tr_direction direction )
|
||||
{
|
||||
assert( direction == TR_UP || direction == TR_DOWN );
|
||||
|
||||
if( direction == TR_DOWN )
|
||||
{
|
||||
return TRUE; /* FIXME -- is there a good way to test for this? */
|
||||
}
|
||||
else
|
||||
{
|
||||
return EVBUFFER_LENGTH( EVBUFFER_OUTPUT( io->bufev ) )
|
||||
|| EVBUFFER_LENGTH( io->output );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tr_peerIoWrite( tr_peerIo * io,
|
||||
const void * writeme,
|
||||
|
|
|
@ -128,9 +128,6 @@ void tr_peerIoSetIOFuncs ( tr_peerIo * io,
|
|||
***
|
||||
**/
|
||||
|
||||
int tr_peerIoWantsBandwidth ( const tr_peerIo * io,
|
||||
tr_direction direction );
|
||||
|
||||
void tr_peerIoWrite ( tr_peerIo * io,
|
||||
const void * writeme,
|
||||
size_t writemeLen,
|
||||
|
|
|
@ -42,11 +42,11 @@ struct tr_shared
|
|||
int bindSocket;
|
||||
int publicPort;
|
||||
|
||||
tr_handle * h;
|
||||
tr_timer * pulseTimer;
|
||||
tr_timer * pulseTimer;
|
||||
|
||||
tr_upnp * upnp;
|
||||
tr_natpmp * natpmp;
|
||||
tr_upnp * upnp;
|
||||
tr_natpmp * natpmp;
|
||||
tr_session * session;
|
||||
};
|
||||
|
||||
/***
|
||||
|
@ -145,16 +145,15 @@ incomingPeersPulse( tr_shared * s )
|
|||
if( s->bindSocket < 0 )
|
||||
break;
|
||||
|
||||
socket = tr_netAccept( s->bindSocket, &addr, &port );
|
||||
socket = tr_netAccept( s->session, s->bindSocket, &addr, &port );
|
||||
if( socket < 0 )
|
||||
break;
|
||||
|
||||
tr_deepLog( __FILE__, __LINE__, NULL,
|
||||
"New INCOMING connection %d (%s)",
|
||||
socket, tr_peerIoAddrStr( &addr,
|
||||
port ) );
|
||||
socket, tr_peerIoAddrStr( &addr, port ) );
|
||||
|
||||
tr_peerMgrAddIncoming( s->h->peerMgr, &addr, port, socket );
|
||||
tr_peerMgrAddIncoming( s->session->peerMgr, &addr, port, socket );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,7 +176,7 @@ sharedPulse( void * vshared )
|
|||
tr_netClose( shared->bindSocket );
|
||||
tr_natpmpClose( shared->natpmp );
|
||||
tr_upnpClose( shared->upnp );
|
||||
shared->h->shared = NULL;
|
||||
shared->session->shared = NULL;
|
||||
tr_free( shared );
|
||||
keepPulsing = 0;
|
||||
}
|
||||
|
@ -190,19 +189,19 @@ sharedPulse( void * vshared )
|
|||
***/
|
||||
|
||||
tr_shared *
|
||||
tr_sharedInit( tr_handle * h,
|
||||
int isEnabled,
|
||||
int publicPort )
|
||||
tr_sharedInit( tr_session * session,
|
||||
int isEnabled,
|
||||
int publicPort )
|
||||
{
|
||||
tr_shared * s = tr_new0( tr_shared, 1 );
|
||||
|
||||
s->h = h;
|
||||
s->session = session;
|
||||
s->publicPort = publicPort;
|
||||
s->bindPort = -1;
|
||||
s->bindSocket = -1;
|
||||
s->natpmp = tr_natpmpInit( );
|
||||
s->upnp = tr_upnpInit( );
|
||||
s->pulseTimer = tr_timerNew( h, sharedPulse, s, 1000 );
|
||||
s->pulseTimer = tr_timerNew( session, sharedPulse, s, 1000 );
|
||||
s->isEnabled = isEnabled ? 1 : 0;
|
||||
s->upnpStatus = TR_PORT_UNMAPPED;
|
||||
s->natpmpStatus = TR_PORT_UNMAPPED;
|
||||
|
@ -224,7 +223,7 @@ tr_sharedSetPort( tr_shared * s,
|
|||
|
||||
s->publicPort = port;
|
||||
|
||||
while( ( tor = tr_torrentNext( s->h, tor ) ) )
|
||||
while( ( tor = tr_torrentNext( s->session, tor ) ) )
|
||||
tr_torrentChangeMyPort( tor );
|
||||
}
|
||||
|
||||
|
|
|
@ -258,6 +258,7 @@ tr_sessionInitFull( const char * configDir,
|
|||
h->pieceSpeed[TR_CLIENT_TO_PEER] = tr_rcInit( );
|
||||
h->rawSpeed[TR_PEER_TO_CLIENT] = tr_rcInit( );
|
||||
h->rawSpeed[TR_CLIENT_TO_PEER] = tr_rcInit( );
|
||||
h->so_sndbuf = 1500 * 3; /* 3x MTU for most ethernet/wireless */
|
||||
|
||||
if( configDir == NULL )
|
||||
configDir = tr_getDefaultConfigDir( );
|
||||
|
|
|
@ -105,6 +105,9 @@ struct tr_handle
|
|||
struct tr_metainfo_lookup * metainfoLookup;
|
||||
int metainfoLookupCount;
|
||||
|
||||
/* the size of the output buffer for peer connections */
|
||||
int so_sndbuf;
|
||||
|
||||
/* the rate at which pieces are being transferred between client and peer.
|
||||
* protocol overhead is NOT included; this is only the piece data */
|
||||
struct tr_ratecontrol * pieceSpeed[2];
|
||||
|
|
Loading…
Add table
Reference in a new issue