From: Juliusz Chroboczek Date: Fri, 18 Feb 2011 00:36:09 +0000 (+0000) Subject: Implement pacing of reads. X-Git-Tag: 2.30b1~324 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dae7db8e101c7f996940ba942e7887721cb4d8a5;p=transmission Implement pacing of reads. 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? --- diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index 355987c06..fbb0c6190 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -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); + } } /***