Ticket #4592: bandwidth.c.patch

File bandwidth.c.patch, 1.5 KB (added by Algorithmus, 11 years ago)
  • libtransmission/bandwidth.c

     
    205205     * peers from starving the others. Loop through the peers, giving each a
    206206     * small chunk of bandwidth. Keep looping until we run out of bandwidth
    207207     * and/or peers that can use it */
    208208    n = peerCount;
    209209    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 */
    211210    while( n > 0 )
    212211    {
     212        i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a peer at random */
     213
    213214        /* value of 3000 bytes chosen so that when using uTP we'll send a full-size
    214215         * frame right away and leave enough buffered data for the next frame to go
    215216         * out in a timely manner. */
    216217        const size_t increment = 3000;
    217218
    218219        const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment );
    219220
    220221        dbgmsg( "peer #%d of %d used %d bytes in this pass", i, n, bytesUsed );
    221222
    222         if( bytesUsed == (int)increment )
    223             ++i;
    224         else {
     223        if( bytesUsed != (int)increment ) {
    225224            /* peer is done writing for now; move it to the end of the list */
    226225            tr_peerIo * pio = peers[i];
    227226            peers[i] = peers[n-1];
    228227            peers[n-1] = pio;
    229228            --n;
    230229        }
    231 
    232         if( i >= n )
    233             i = 0;
    234230    }
    235231}
    236232
    237233void
    238234tr_bandwidthAllocate( tr_bandwidth  * b,