Implement pacing of reads.
authorJuliusz Chroboczek <jch@pps.univ-paris-diderot.fr>
Fri, 18 Feb 2011 00:36:09 +0000 (00:36 +0000)
committerJuliusz Chroboczek <jch@pps.univ-paris-diderot.fr>
Fri, 18 Feb 2011 00:36:09 +0000 (00:36 +0000)
This should cause uTP sockets to respect read bandwidth limits.  I'm not so
sure about the values we return for the read buffer size -- perhaps we
should allow some slack for network latency?

libtransmission/peer-io.c

index 355987c06ff2caaf6eae4d897ad2f9d9a296c3db..fbb0c6190037e2cf62cd16850422bad26a3ff2e3 100644 (file)
@@ -408,10 +408,18 @@ static size_t
 utp_get_rb_size(void *closure)
 {
     tr_peerIo *io = (tr_peerIo *)closure;
+    size_t bytes;
     assert( tr_isPeerIo( io ) );
 
-    tr_ndbg( "UTP", "Get RB size" );
-    return 0;
+    if( io->read_enabled )
+        bytes =
+            tr_bandwidthClamp( &io->bandwidth, TR_DOWN, UTP_READ_BUFFER_SIZE );
+    else
+        bytes = 0;
+
+    tr_ndbg( "UTP", "Get RB size %ld", (long)bytes);
+
+    return UTP_READ_BUFFER_SIZE - bytes;
 }
 
 static void
@@ -706,8 +714,11 @@ tr_peerIoSetEnabled( tr_peerIo    * io,
 
     if( dir == TR_UP )
         io->write_enabled = isEnabled;
-    else if( dir == TR_DOWN )
+    else if( dir == TR_DOWN ) {
         io->read_enabled = isEnabled;
+        if( io->utp_socket && isEnabled )
+            UTP_RBDrained(io->utp_socket);
+    }
 }
 
 /***