fix for bug in bandwidth throttler when limiting a torrent to lower than bandwidth block size. Fixed #ifndef related to DHT support

This commit is contained in:
Arvid Norberg 2007-02-19 00:01:39 +00:00
parent 16457e2280
commit 9c0e9701d9
3 changed files with 14 additions and 5 deletions

View File

@ -108,7 +108,6 @@ struct bandwidth_limit
void assign(int amount)
{
assert(amount > 0);
assert(amount <= max_assignable());
m_current_rate += amount;
m_quota_left += amount;
}
@ -121,7 +120,7 @@ struct bandwidth_limit
int quota_left() const
{
return m_quota_left;
return (std::max)(m_quota_left, 0);
}
void expire(int amount)

View File

@ -471,6 +471,7 @@ namespace libtorrent
int prioritize_tracker(int tracker_index);
void on_country_lookup(asio::error_code const& error, tcp::resolver::iterator i
, boost::intrusive_ptr<peer_connection> p) const;
bool request_bandwidth_from_session(int channel) const;
torrent_info m_torrent_file;

View File

@ -1856,16 +1856,25 @@ namespace libtorrent
}
}
bool torrent::request_bandwidth_from_session(int channel) const
{
int max_assignable = m_bandwidth_limit[channel].max_assignable();
return max_assignable > max_bandwidth_block_size
|| (m_bandwidth_limit[channel].throttle() < m_bandwidth_limit[channel].max_assignable())
&& max_assignable > 0;
}
void torrent::request_bandwidth(int channel
, boost::intrusive_ptr<peer_connection> p
, bool non_prioritized)
{
if (m_bandwidth_limit[channel].max_assignable() >= max_bandwidth_block_size)
if (request_bandwidth_from_session(channel))
{
if (channel == peer_connection::upload_channel)
m_ses.m_ul_bandwidth_manager.request_bandwidth(p, non_prioritized);
else if (channel == peer_connection::download_channel)
m_ses.m_dl_bandwidth_manager.request_bandwidth(p, non_prioritized);
m_bandwidth_limit[channel].assign(max_bandwidth_block_size);
}
else
@ -1883,7 +1892,7 @@ namespace libtorrent
m_bandwidth_limit[channel].expire(amount);
while (!m_bandwidth_queue[channel].empty()
&& m_bandwidth_limit[channel].max_assignable() >= max_bandwidth_block_size)
&& request_bandwidth_from_session(channel))
{
bw_queue_entry qe = m_bandwidth_queue[channel].front();
m_bandwidth_queue[channel].pop_front();
@ -1986,7 +1995,7 @@ namespace libtorrent
m_currently_trying_tracker = 0;
m_next_request = second_clock::universal_time() + seconds(delay);
#ifndef DISABLE_DHT_SUPPORT
#ifndef TORRENT_DISABLE_DHT
// only start the dht announce unless we already are already running
// the announce timer (a positive expiration time indicates
// that it's running)