fixed division by zero problem in allocate_resources, removed incorrect asserts

This commit is contained in:
Arvid Norberg 2006-11-22 12:15:47 +00:00
parent 8e289bb233
commit 1015864eeb
2 changed files with 3 additions and 14 deletions

View File

@ -192,6 +192,7 @@ namespace libtorrent
// a consumer that uses 95% or more of its assigned
// quota is considered saturating
size_type used = r.used;
if (r.given == 0) continue;
if (used * 20 / r.given >= 19)
{
++num_saturated;
@ -233,7 +234,7 @@ namespace libtorrent
int target;
size_type used = r.used;
if (used * 20 / r.given >= 19)
if (r.given > 0 && used * 20 / r.given >= 19)
{
assert(num_saturated > 0);
target = div_round_up(saturated_sum, num_saturated);

View File

@ -992,19 +992,6 @@ namespace libtorrent { namespace detail
, m_torrents
, &torrent::m_dl_bandwidth_quota);
#ifndef NDEBUG
size_type sum_ul = 0;
size_type sum_dl = 0;
for (torrent_map::iterator i = m_torrents.begin();
i != m_torrents.end(); ++i)
{
sum_ul += i->second->m_ul_bandwidth_quota.given;
sum_dl += i->second->m_dl_bandwidth_quota.given;
}
assert(m_upload_rate == -1 || sum_ul == int(m_upload_rate * tick_interval));
assert(m_download_rate == -1 || sum_dl == int(m_download_rate * tick_interval));
#endif
allocate_resources(m_max_uploads == -1
? std::numeric_limits<int>::max()
: m_max_uploads
@ -1521,6 +1508,7 @@ namespace libtorrent { namespace detail
void session_impl::start_dht(entry const& startup_state)
{
mutex_t::scoped_lock l(m_mutex);
m_dht.reset();
m_dht.reset(new dht::dht_tracker(m_selector
, m_dht_settings, m_listen_interface.address()
, startup_state));