Ticket #4592: bandwidth.c.patch
File bandwidth.c.patch, 1.5 KB (added by Algorithmus, 11 years ago) |
---|
-
libtransmission/bandwidth.c
205 205 * peers from starving the others. Loop through the peers, giving each a 206 206 * small chunk of bandwidth. Keep looping until we run out of bandwidth 207 207 * and/or peers that can use it */ 208 208 n = peerCount; 209 209 dbgmsg( "%d peers to go round-robin for %s", n, (dir==TR_UP?"upload":"download") ); 210 i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a random starting point */211 210 while( n > 0 ) 212 211 { 212 i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a peer at random */ 213 213 214 /* value of 3000 bytes chosen so that when using uTP we'll send a full-size 214 215 * frame right away and leave enough buffered data for the next frame to go 215 216 * out in a timely manner. */ 216 217 const size_t increment = 3000; 217 218 218 219 const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment ); 219 220 220 221 dbgmsg( "peer #%d of %d used %d bytes in this pass", i, n, bytesUsed ); 221 222 222 if( bytesUsed == (int)increment ) 223 ++i; 224 else { 223 if( bytesUsed != (int)increment ) { 225 224 /* peer is done writing for now; move it to the end of the list */ 226 225 tr_peerIo * pio = peers[i]; 227 226 peers[i] = peers[n-1]; 228 227 peers[n-1] = pio; 229 228 --n; 230 229 } 231 232 if( i >= n )233 i = 0;234 230 } 235 231 } 236 232 237 233 void 238 234 tr_bandwidthAllocate( tr_bandwidth * b,