]> granicus.if.org Git - transmission/commitdiff
(trunk libT) make sure that outbound protocol messages don't get blocked by bandwidth...
authorCharles Kerr <charles@transmissionbt.com>
Tue, 21 Apr 2009 16:18:51 +0000 (16:18 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 21 Apr 2009 16:18:51 +0000 (16:18 +0000)
libtransmission/bandwidth.c
libtransmission/peer-io.c
libtransmission/peer-io.h

index 50cc144fd878aa111d17e1e885eaf479831482c1..4672cfdde030bb110a66958fe7a9235e267bd838 100644 (file)
@@ -251,12 +251,17 @@ tr_bandwidthAllocate( tr_bandwidth  * b,
     peers = (struct tr_peerIo**) tr_ptrArrayBase( &tmp );
     peerCount = tr_ptrArraySize( &tmp );
 
-    for( i=0; i<peerCount; ++i ) {
-        tr_peerIoRef( peers[i] );
-        switch( peers[i]->priority ) {
-            case TR_PRI_HIGH: tr_ptrArrayAppend( &high,   peers[i] ); break;
-            case TR_PRI_LOW:  tr_ptrArrayAppend( &low,    peers[i] ); break;
-            default:          tr_ptrArrayAppend( &normal, peers[i] ); break;
+    for( i=0; i<peerCount; ++i )
+    {
+        tr_peerIo * io = peers[i];
+        tr_peerIoRef( io );
+
+        tr_peerIoFlushOutgoingProtocolMsgs( io );
+
+        switch( io->priority ) {
+            case TR_PRI_HIGH: tr_ptrArrayAppend( &high,   io ); break;
+            case TR_PRI_LOW:  tr_ptrArrayAppend( &low,    io ); break;
+            default:          tr_ptrArrayAppend( &normal, io ); break;
         }
     }
 
index 9877c551a6718eda467b4bef56d45ceb0affc162..5e4b73b26a6c3b9c0aa4e9586944d46c7d270001 100644 (file)
@@ -39,7 +39,7 @@
 #define MAGIC_NUMBER 206745
 
 static size_t
-getPacketOverhead( size_t d )
+guessPacketOverhead( size_t d )
 {
     /**
      * http://sd.wareonearth.com/~phil/net/overhead/
@@ -90,7 +90,7 @@ didWriteWrapper( tr_peerIo * io, size_t bytes_transferred )
      {
         struct tr_datatype * next = __tr_list_entry( io->outbuf_datatypes.next, struct tr_datatype, head );
         const size_t payload = MIN( next->length, bytes_transferred );
-        const size_t overhead = getPacketOverhead( payload );
+        const size_t overhead = guessPacketOverhead( payload );
 
         tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData );
 
@@ -847,6 +847,26 @@ tr_peerIoFlush( tr_peerIo  * io, tr_direction dir, size_t limit )
     return bytesUsed;
 }
 
+int
+tr_peerIoFlushOutgoingProtocolMsgs( tr_peerIo * io )
+{
+    size_t byteCount = 0;
+    struct __tr_list * walk;
+    struct __tr_list * fencepost = &io->outbuf_datatypes;
+
+    /* count up how many bytes are used by non-piece-data messages
+       at the front of our outbound queue */
+    for( walk=fencepost->next; walk!=fencepost; walk=walk->next ) {
+        struct tr_datatype * d = __tr_list_entry( walk, struct tr_datatype, head );
+        if( d->isPieceData )
+            break;
+        byteCount += d->length;
+    }
+
+    return tr_peerIoFlush( io, TR_UP, byteCount );
+}
+
+
 /***
 ****
 ****/
index 7a45061b88f2b8e461f9db2d8c0a36800cd76f9d..adb9afcb670a57148d1a07cf54455e0bb3157afd 100644 (file)
@@ -380,6 +380,8 @@ int       tr_peerIoFlush( tr_peerIo     * io,
                           tr_direction    dir,
                           size_t          byteLimit );
 
+int       tr_peerIoFlushOutgoingProtocolMsgs( tr_peerIo * io );
+
 /**
 ***
 **/