mirror of
https://github.com/transmission/transmission
synced 2024-12-25 17:17:31 +00:00
(libT) dead code removal
This commit is contained in:
parent
59c2a61971
commit
b5c2f14387
7 changed files with 25 additions and 72 deletions
|
@ -60,7 +60,6 @@ fi
|
|||
AC_HEADER_STDC
|
||||
AC_HEADER_TIME
|
||||
AC_CHECK_FUNCS([lrintf strlcpy daemon dirname basename daemon strcasecmp])
|
||||
AC_CHECK_SIZEOF([void*])
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
ACX_PTHREAD
|
||||
|
|
|
@ -52,12 +52,6 @@
|
|||
#include "platform.h" /* tr_lock */
|
||||
#include "utils.h"
|
||||
|
||||
#if SIZEOF_VOIDP == 8
|
||||
#define TR_UINT_TO_PTR( i ) (void*)( (uint64_t)i )
|
||||
#else
|
||||
#define TR_UINT_TO_PTR( i ) ( (void*)( (uint32_t)i ) )
|
||||
#endif
|
||||
|
||||
#define dbgmsg( ... ) tr_deepLog( __FILE__, __LINE__, NULL, __VA_ARGS__ )
|
||||
|
||||
/**
|
||||
|
@ -84,9 +78,8 @@ struct tr_openfile
|
|||
|
||||
struct tr_fd_s
|
||||
{
|
||||
int reserved;
|
||||
int normal;
|
||||
int normalMax;
|
||||
int socketCount;
|
||||
int socketMax;
|
||||
tr_lock * lock;
|
||||
struct tr_openfile open[TR_MAX_OPEN_FILES];
|
||||
};
|
||||
|
@ -368,54 +361,28 @@ tr_fdFileClose( const char * filename )
|
|||
****
|
||||
***/
|
||||
|
||||
static tr_list * reservedSockets = NULL;
|
||||
|
||||
static void
|
||||
setSocketPriority( int fd,
|
||||
int isReserved )
|
||||
{
|
||||
if( isReserved )
|
||||
tr_list_append( &reservedSockets, TR_UINT_TO_PTR( fd ) );
|
||||
}
|
||||
|
||||
static int
|
||||
socketWasReserved( int fd )
|
||||
{
|
||||
return tr_list_remove_data( &reservedSockets,
|
||||
TR_UINT_TO_PTR( fd ) ) != NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
getSocketMax( struct tr_fd_s * gFd )
|
||||
{
|
||||
return gFd->normalMax;
|
||||
return gFd->socketMax;
|
||||
}
|
||||
|
||||
int
|
||||
tr_fdSocketCreate( int type,
|
||||
int isReserved )
|
||||
tr_fdSocketCreate( int type )
|
||||
{
|
||||
int s = -1;
|
||||
|
||||
tr_lockLock( gFd->lock );
|
||||
|
||||
if( isReserved || ( gFd->normal < getSocketMax( gFd ) ) )
|
||||
if( gFd->socketCount < getSocketMax( gFd ) )
|
||||
if( ( s = socket( AF_INET, type, 0 ) ) < 0 )
|
||||
tr_err( _( "Couldn't create socket: %s" ),
|
||||
tr_strerror( sockerrno ) );
|
||||
|
||||
if( s > -1 )
|
||||
{
|
||||
setSocketPriority( s, isReserved );
|
||||
++gFd->socketCount;
|
||||
|
||||
if( isReserved )
|
||||
++gFd->reserved;
|
||||
else
|
||||
++gFd->normal;
|
||||
}
|
||||
|
||||
assert( gFd->reserved >= 0 );
|
||||
assert( gFd->normal >= 0 );
|
||||
assert( gFd->socketCount >= 0 );
|
||||
|
||||
tr_lockUnlock( gFd->lock );
|
||||
return s;
|
||||
|
@ -434,17 +401,16 @@ tr_fdSocketAccept( int b,
|
|||
assert( port );
|
||||
|
||||
tr_lockLock( gFd->lock );
|
||||
if( gFd->normal < getSocketMax( gFd ) )
|
||||
if( gFd->socketCount < getSocketMax( gFd ) )
|
||||
{
|
||||
len = sizeof( sock );
|
||||
s = accept( b, (struct sockaddr *) &sock, &len );
|
||||
}
|
||||
if( s > -1 )
|
||||
{
|
||||
setSocketPriority( s, FALSE );
|
||||
*addr = sock.sin_addr;
|
||||
*port = sock.sin_port;
|
||||
gFd->normal++;
|
||||
++gFd->socketCount;
|
||||
}
|
||||
tr_lockUnlock( gFd->lock );
|
||||
|
||||
|
@ -469,14 +435,10 @@ tr_fdSocketClose( int s )
|
|||
if( s >= 0 )
|
||||
{
|
||||
socketClose( s );
|
||||
if( socketWasReserved( s ) )
|
||||
--gFd->reserved;
|
||||
else
|
||||
--gFd->normal;
|
||||
--gFd->socketCount;
|
||||
}
|
||||
|
||||
assert( gFd->reserved >= 0 );
|
||||
assert( gFd->normal >= 0 );
|
||||
assert( gFd->socketCount >= 0 );
|
||||
|
||||
tr_lockUnlock( gFd->lock );
|
||||
}
|
||||
|
@ -503,11 +465,11 @@ tr_fdInit( int globalPeerLimit )
|
|||
rlim.rlim_cur = MIN( rlim.rlim_max,
|
||||
(rlim_t)( globalPeerLimit + NOFILE_BUFFER ) );
|
||||
setrlimit( RLIMIT_NOFILE, &rlim );
|
||||
gFd->normalMax = rlim.rlim_cur - NOFILE_BUFFER;
|
||||
gFd->socketMax = rlim.rlim_cur - NOFILE_BUFFER;
|
||||
tr_dbg( "setrlimit( RLIMIT_NOFILE, %d )", (int)rlim.rlim_cur );
|
||||
}
|
||||
#else
|
||||
gFd->normalMax = globalPeerLimit;
|
||||
gFd->socketMax = globalPeerLimit;
|
||||
#endif
|
||||
tr_dbg( "%d usable file descriptors", globalPeerLimit );
|
||||
|
||||
|
@ -526,7 +488,6 @@ tr_fdClose( void )
|
|||
|
||||
tr_lockFree( gFd->lock );
|
||||
|
||||
tr_list_free( &reservedSockets, NULL );
|
||||
tr_free( gFd );
|
||||
}
|
||||
|
||||
|
@ -534,12 +495,12 @@ void
|
|||
tr_fdSetPeerLimit( uint16_t n )
|
||||
{
|
||||
assert( gFd != NULL && "tr_fdInit() must be called first!" );
|
||||
gFd->normalMax = n;
|
||||
gFd->socketMax = n;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
tr_fdGetPeerLimit( void )
|
||||
{
|
||||
return gFd ? gFd->normalMax : -1;
|
||||
return gFd ? gFd->socketMax : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -79,8 +79,7 @@ void tr_fdFileClose( const char * filename );
|
|||
/***********************************************************************
|
||||
* Sockets
|
||||
**********************************************************************/
|
||||
int tr_fdSocketCreate( int type,
|
||||
int priority );
|
||||
int tr_fdSocketCreate( int type );
|
||||
|
||||
int tr_fdSocketAccept( int b,
|
||||
struct in_addr * addr,
|
||||
|
|
|
@ -117,12 +117,9 @@ makeSocketNonBlocking( int fd )
|
|||
}
|
||||
|
||||
static int
|
||||
createSocket( int type,
|
||||
int priority )
|
||||
createSocket( int type )
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = tr_fdSocketCreate( type, priority );
|
||||
int fd = tr_fdSocketCreate( type );
|
||||
|
||||
if( fd >= 0 )
|
||||
fd = makeSocketNonBlocking( fd );
|
||||
|
@ -140,14 +137,13 @@ createSocket( int type,
|
|||
|
||||
int
|
||||
tr_netOpenTCP( const struct in_addr * addr,
|
||||
tr_port_t port,
|
||||
int priority )
|
||||
tr_port_t port )
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_in sock;
|
||||
const int type = SOCK_STREAM;
|
||||
|
||||
if( ( s = createSocket( type, priority ) ) < 0 )
|
||||
if( ( s = createSocket( type ) ) < 0 )
|
||||
return -1;
|
||||
|
||||
memset( &sock, 0, sizeof( sock ) );
|
||||
|
@ -187,7 +183,7 @@ tr_netBindTCP( int port )
|
|||
int optval;
|
||||
#endif
|
||||
|
||||
if( ( s = createSocket( type, 1 ) ) < 0 )
|
||||
if( ( s = createSocket( type ) ) < 0 )
|
||||
return -1;
|
||||
|
||||
#ifdef SO_REUSEADDR
|
||||
|
|
|
@ -70,8 +70,7 @@ int tr_netResolve( const char *,
|
|||
* Sockets
|
||||
**********************************************************************/
|
||||
int tr_netOpenTCP( const struct in_addr * addr,
|
||||
tr_port_t port,
|
||||
int priority );
|
||||
tr_port_t port );
|
||||
|
||||
int tr_netBindTCP( int port );
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ tr_peerIoNewOutgoing( tr_session * session,
|
|||
assert( port >= 0 );
|
||||
assert( torrentHash );
|
||||
|
||||
socket = tr_netOpenTCP( in_addr, port, 0 );
|
||||
socket = tr_netOpenTCP( in_addr, port );
|
||||
|
||||
return socket < 0
|
||||
? NULL
|
||||
|
@ -451,7 +451,7 @@ tr_peerIoReconnect( tr_peerIo * io )
|
|||
if( io->socket >= 0 )
|
||||
tr_netClose( io->socket );
|
||||
|
||||
io->socket = tr_netOpenTCP( &io->in_addr, io->port, 0 );
|
||||
io->socket = tr_netOpenTCP( &io->in_addr, io->port );
|
||||
|
||||
if( io->socket >= 0 )
|
||||
{
|
||||
|
|
|
@ -2504,8 +2504,7 @@ allocateBandwidth( tr_peerMgr * mgr,
|
|||
{
|
||||
Torrent * t = torrents[i];
|
||||
const size_t used = countPeerBandwidth( t->peers, direction );
|
||||
+countHandshakeBandwidth( t->outgoingHandshakes,
|
||||
direction );
|
||||
countHandshakeBandwidth( t->outgoingHandshakes, direction );
|
||||
|
||||
/* add this torrent's bandwidth use to allBytesUsed */
|
||||
allBytesUsed += used;
|
||||
|
|
Loading…
Reference in a new issue