mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 17:49:52 +01:00
fix: Band-Aid fix for utp speed limit (#7541)
* fix: don't clamp in `can_read_wrapper()` for TCP * fix: notify bandwidth different in utp and TCP
This commit is contained in:
@@ -350,7 +350,7 @@ void tr_peerIo::can_read_wrapper(size_t bytes_transferred)
|
||||
auto done = false;
|
||||
auto err = false;
|
||||
|
||||
if (bytes_transferred > 0U)
|
||||
if (socket_.is_tcp() && bytes_transferred > 0U)
|
||||
{
|
||||
bandwidth().notify_bandwidth_consumed(TR_DOWN, bytes_transferred, false, now);
|
||||
}
|
||||
@@ -358,19 +358,27 @@ void tr_peerIo::can_read_wrapper(size_t bytes_transferred)
|
||||
// In normal conditions, only continue processing if we still have bandwidth
|
||||
// quota for it.
|
||||
//
|
||||
// The read buffer will grow indefinitely if libutp or the TCP stack keeps buffering
|
||||
// data faster than the bandwidth limit allows. To safeguard against that, we keep
|
||||
// The read buffer will grow indefinitely if libutp keeps buffering data faster
|
||||
// than the bandwidth limit allows. To safeguard against that, we keep
|
||||
// processing if the read buffer is more than twice as large as the target size.
|
||||
while (!done && !err && (read_buffer_size() > RcvBuf * 2U || bandwidth().clamp(TR_DOWN, read_buffer_size()) != 0U))
|
||||
while (!done && !err &&
|
||||
(socket_.is_tcp() || read_buffer_size() > RcvBuf * 2U || bandwidth().clamp(TR_DOWN, read_buffer_size()) != 0U))
|
||||
{
|
||||
auto piece = size_t{};
|
||||
auto const old_size = read_buffer_size();
|
||||
auto const read_state = can_read_ != nullptr ? can_read_(this, user_data_, &piece) : ReadState::Err;
|
||||
auto const used = old_size - read_buffer_size();
|
||||
|
||||
if (piece > 0U)
|
||||
{
|
||||
bandwidth().notify_bandwidth_consumed(TR_DOWN, piece, true, now);
|
||||
}
|
||||
|
||||
if (socket_.is_utp() && used > 0U)
|
||||
{
|
||||
bandwidth().notify_bandwidth_consumed(TR_DOWN, used, false, now);
|
||||
}
|
||||
|
||||
switch (read_state)
|
||||
{
|
||||
case ReadState::Now:
|
||||
|
||||
Reference in New Issue
Block a user