diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 3873700b7..36e7db4d6 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -206,6 +206,8 @@ namespace libtorrent void expire_bandwidth(int channel, int amount); void assign_bandwidth(int channel, int amount); + + int bandwidth_throttle(int channel) const; // -------------------------------------------- // PEER MANAGEMENT diff --git a/src/bandwidth_manager.cpp b/src/bandwidth_manager.cpp index 59aaeaf9d..a5868d439 100644 --- a/src/bandwidth_manager.cpp +++ b/src/bandwidth_manager.cpp @@ -218,6 +218,10 @@ namespace libtorrent t->expire_bandwidth(m_channel, -1); continue; } + // don't hand out chunks larger than the throttle + // per second on the torrent + if (max_assignable > t->bandwidth_throttle(m_channel)) + max_assignable = t->bandwidth_throttle(m_channel); // so, hand out max_assignable, but no more than // the available bandwidth (amount) and no more diff --git a/src/storage.cpp b/src/storage.cpp index ed1ae0a68..23e1e99ea 100755 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -91,11 +91,13 @@ namespace libtorrent catch (std::exception) { std::wstring ret; - for (const char* i = &s[0]; i < &s[0] + s.size(); ++i) + const char* end = &s[0] + s.size(); + for (const char* i = &s[0]; i < end;) { - wchar_t c; - c = '.'; - std::mbtowc(&c, i, 1); + wchar_t c = '.'; + int result = std::mbtowc(&c, i, end - i); + if (result > 0) i += result; + else ++i; ret += c; } return ret; diff --git a/src/torrent.cpp b/src/torrent.cpp index 29049a34e..3ce495c20 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1861,7 +1861,12 @@ namespace libtorrent int max_assignable = m_bandwidth_limit[channel].max_assignable(); return max_assignable > max_bandwidth_block_size || (m_bandwidth_limit[channel].throttle() < max_bandwidth_block_size - && max_assignable > 0); + && max_assignable == m_bandwidth_limit[channel].throttle()); + } + + int torrent::bandwidth_throttle(int channel) const + { + return m_bandwidth_limit[channel].throttle(); } void torrent::request_bandwidth(int channel