]> granicus.if.org Git - transmission/commitdiff
(libT) dead code removal
authorCharles Kerr <charles@transmissionbt.com>
Tue, 14 Oct 2008 20:44:41 +0000 (20:44 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 14 Oct 2008 20:44:41 +0000 (20:44 +0000)
configure.ac
libtransmission/fdlimit.c
libtransmission/fdlimit.h
libtransmission/net.c
libtransmission/net.h
libtransmission/peer-io.c
libtransmission/peer-mgr.c

index 979603bd0cdf50433e48f2d33660e091a2f82354..4855f9bbf082341c3be0caa746d4075958e08248 100644 (file)
@@ -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
index 0bc46f80e2dd85e87bba051199634940491fdd06..0754b0d38e0fccb1d8c6043dc548a95f1cee52e1 100644 (file)
 #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;
 }
 
index ec2d637254f1368f62a7bc68dfba07e87457568c..63c4c7c7e951a7ac5a68671a45508cf20ebca287 100644 (file)
@@ -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,
index 594fc44d5d814f7c9600e94597d9b6574da268f8..02b628759118090e613b5a6b96052c77040c2259 100644 (file)
@@ -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
index 433a44576e472445b946618b63d8780b23ea8def..988ad45f167b366e5e8513b671241e7684901ebc 100644 (file)
@@ -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 );
 
index 9950c5441f90a15164e7a490a8219c7f25331036..08d76e29f978aac0a857abbef87b5a92848c9d0c 100644 (file)
@@ -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 )
     {
index 2c5b6c70b3e653fb4d52ddc88c45e9e944cffce5..a85117969972d71234de3ec8c277eb6e88833175 100644 (file)
@@ -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;