]> granicus.if.org Git - transmission/commitdiff
minor code cleanup
authorCharles Kerr <charles@transmissionbt.com>
Sun, 23 Nov 2008 16:30:09 +0000 (16:30 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 23 Nov 2008 16:30:09 +0000 (16:30 +0000)
libtransmission/peer-msgs.c
libtransmission/ptrarray.h
libtransmission/transmission.h

index add0abaf4281dfe08d23f50c57b4333667a51d7a..93ba50d370bd65fb1643e7364d2636fe740b4e17 100644 (file)
@@ -344,7 +344,11 @@ myDebug( const char *               file,
     }
 }
 
-#define dbgmsg( msgs, ... ) myDebug( __FILE__, __LINE__, msgs, __VA_ARGS__ )
+#define dbgmsg( msgs, ... ) \
+    do { \
+        if( tr_deepLoggingIsActive( ) ) \
+            myDebug( __FILE__, __LINE__, msgs, __VA_ARGS__ ); \
+    } while( 0 )
 
 /**
 ***
@@ -910,7 +914,8 @@ tr_peerMsgsAddRequest( tr_peermsgs *    msgs,
     ***  Accept this request
     **/
 
-    dbgmsg( msgs, "added req for piece %lu", (unsigned long)index );
+    dbgmsg( msgs, "adding req for %"PRIu32":%"PRIu32"->%"PRIu32" to our `will request' list",
+            index, offset, length );
     req.time_requested = time( NULL );
     reqListAppend( &msgs->clientWillAskFor, &req );
     return TR_ADDREQ_OK;
@@ -922,6 +927,7 @@ cancelAllRequestsToPeer( tr_peermsgs * msgs )
     int                 i;
     struct request_list a = msgs->clientWillAskFor;
     struct request_list b = msgs->clientAskedFor;
+    dbgmsg( msgs, "cancelling all requests to peer" );
 
     msgs->clientAskedFor = REQUEST_LIST_INIT;
     msgs->clientWillAskFor = REQUEST_LIST_INIT;
@@ -949,17 +955,21 @@ tr_peerMsgsCancel( tr_peermsgs * msgs,
     assert( msgs != NULL );
     assert( length > 0 );
 
+
     /* have we asked the peer for this piece? */
     req.index = pieceIndex;
     req.offset = offset;
     req.length = length;
 
     /* if it's only in the queue and hasn't been sent yet, free it */
-    if( reqListRemove( &msgs->clientWillAskFor, &req ) )
+    if( reqListRemove( &msgs->clientWillAskFor, &req ) ) {
+        dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32"\n", pieceIndex, offset, length );
         fireCancelledReq( msgs, &req );
+    }
 
     /* if it's already been sent, send a cancel message too */
     if( reqListRemove( &msgs->clientAskedFor, &req ) ) {
+        dbgmsg( msgs, "cancelling %"PRIu32":%"PRIu32"->%"PRIu32"\n", pieceIndex, offset, length );
         protocolSendCancel( msgs, &req );
         fireCancelledReq( msgs, &req );
     }
@@ -1033,8 +1043,7 @@ parseLtepHandshake( tr_peermsgs *     msgs,
         return;
     }
 
-    dbgmsg( msgs, "here is the ltep handshake we got [%*.*s]", len, len,
-            tmp );
+    dbgmsg( msgs, "here is the handshake: [%*.*s]", len, len,  tmp );
 
     /* does the peer prefer encrypted connections? */
     if( tr_bencDictFindInt( &val, "e", &i ) )
@@ -1690,8 +1699,7 @@ ratePulse( void * vpeer )
                   ( rateToClient * 30 * 1024 ) / peer->torrent->blockSize;
 
     peer->minActiveRequests = 4;
-    peer->maxActiveRequests = peer->minActiveRequests +
-                              estimatedBlocksInNext30Seconds;
+    peer->maxActiveRequests = peer->minActiveRequests + estimatedBlocksInNext30Seconds;
     return TRUE;
 }
 
@@ -1747,11 +1755,10 @@ peerPulse( void * vmsgs )
             dbgmsg( msgs, "started an outMessages batch (length is %zu)", EVBUFFER_LENGTH( msgs->outMessages ) );
             msgs->outMessagesBatchedAt = now;
         }
-        else if( haveMessages
-               && ( ( now - msgs->outMessagesBatchedAt ) >
-                   msgs->outMessagesBatchPeriod ) )
+        else if( ( haveMessages ) &&
+                 ( ( now - msgs->outMessagesBatchedAt ) > msgs->outMessagesBatchPeriod ) )
         {
-            dbgmsg( msgs, "flushing outMessages... (length is %zu)", EVBUFFER_LENGTH( msgs->outMessages ) );
+            dbgmsg( msgs, "flushing outMessages... to %p (length is %zu)", msgs->io, EVBUFFER_LENGTH( msgs->outMessages ) );
             tr_peerIoWriteBuf( msgs->io, msgs->outMessages, FALSE );
             msgs->clientSentAnythingAt = now;
             msgs->outMessagesBatchedAt = 0;
@@ -2014,8 +2021,7 @@ sendPex( tr_peermsgs * msgs )
         tr_peerIoWriteUint8 ( msgs->io, out, msgs->ut_pex_id );
         tr_peerIoWriteBytes ( msgs->io, out, benc, bencLen );
         pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS );
-        dbgmsg( msgs, "outMessage size is now %d",
-               (int)EVBUFFER_LENGTH( out ) );
+        dbgmsg( msgs, "sending a pex message; outMessage size is now %zu", EVBUFFER_LENGTH( out ) );
 
         /* cleanup */
         tr_free( benc );
index 033a64e4598728ef1d9278aa2cf721b9d516d241..d86acc75ed16dbc77dc21852a2a2fa98f1c7c7fb 100644 (file)
@@ -36,9 +36,8 @@ tr_ptrArray * tr_ptrArrayNew( void );
 
 tr_ptrArray * tr_ptrArrayDup( tr_ptrArray* );
 
-void          tr_ptrArrayForeach(
-                        tr_ptrArray*,
-    PtrArrayForeachFunc func );
+void          tr_ptrArrayForeach( tr_ptrArray         * array,
+                                  PtrArrayForeachFunc   func );
 
 void          tr_ptrArrayFree( tr_ptrArray         * array,
                                PtrArrayForeachFunc   func );
index 20d034dae0bb3f59b645d001b6732e0661aef843..4a792ac5ff5cbbed1388711f31e17ba5c660bf6b 100644 (file)
@@ -45,6 +45,9 @@ extern "C" {
 #ifndef PRIu64
  #define PRIu64 "llu"
 #endif
+#ifndef PRIu32
+ #define PRIu32 "lu"
+#endif
 #include <time.h> /* time_t */
 
 #define SHA_DIGEST_LENGTH 20