*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-02-24 12:45:05 +00:00
parent 4cb125a694
commit cea75e3723
4 changed files with 72 additions and 55 deletions

View File

@ -214,7 +214,8 @@ namespace libtorrent
// quota is unlimited.
int send_quota_left() const { return m_send_quota_left; }
void update_send_quota_left() {
void update_send_quota_left()
{
m_send_quota_left = upload_bandwidth.given;
if (m_send_quota_left > 0) send_buffer_updated();
}

View File

@ -35,7 +35,8 @@ POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <boost/limits.hpp>
namespace libtorrent {
namespace libtorrent
{
namespace
{
int saturated_add(int a, int b)
@ -74,7 +75,7 @@ namespace libtorrent {
assert(num_resources > 0);
assert(r->given <= r->wanted);
int accepted=std::min(num_resources, r->wanted - r->given);
int accepted = std::min(num_resources, r->wanted - r->given);
assert(accepted >= 0);
r->given += accepted;
@ -99,48 +100,55 @@ namespace libtorrent {
assert(total_wanted>=0);
return total_wanted;
}
}
#ifndef NDEBUG
class allocate_resources_contract_check
{
int resources;
std::vector<resource_request *> & requests;
public:
allocate_resources_contract_check(int resources_,std::vector<resource_request *> & requests_)
: resources(resources_)
, requests(requests_)
{
assert(resources >= 0);
for(int i=0;i<(int)requests.size();i++)
{
assert(requests[i]->used >= 0);
assert(requests[i]->wanted >= 0);
assert(requests[i]->given >= 0);
}
}
~allocate_resources_contract_check()
class allocate_resources_contract_check
{
int sum_given = 0;
int sum_wanted = 0;
for(int i=0;i<(int)requests.size();i++)
{
assert(requests[i]->used >= 0);
assert(requests[i]->wanted >= 0);
assert(requests[i]->given >= 0);
assert(requests[i]->given <= requests[i]->wanted);
sum_given = saturated_add(sum_given, requests[i]->given);
sum_wanted = saturated_add(sum_wanted, requests[i]->wanted);
int resources;
std::vector<resource_request *> & requests;
public:
allocate_resources_contract_check(
int resources_
, std::vector<resource_request *>& requests_)
: resources(resources_)
, requests(requests_)
{
assert(resources >= 0);
for (int i = 0; i < (int)requests.size(); ++i)
{
assert(requests[i]->used >= 0);
assert(requests[i]->wanted >= 0);
assert(requests[i]->given >= 0);
}
}
assert(sum_given == std::min(resources,sum_wanted));
}
};
~allocate_resources_contract_check()
{
int sum_given = 0;
int sum_wanted = 0;
for (int i = 0; i < (int)requests.size(); ++i)
{
assert(requests[i]->used >= 0);
assert(requests[i]->wanted >= 0);
assert(requests[i]->given >= 0);
assert(requests[i]->given <= requests[i]->wanted);
sum_given = saturated_add(sum_given, requests[i]->given);
sum_wanted = saturated_add(sum_wanted, requests[i]->wanted);
}
assert(sum_given == std::min(resources,sum_wanted));
}
};
#endif
} // namespace unnamed
void allocate_resources(int resources,
std::vector<resource_request *> & requests)
void allocate_resources(int resources
, std::vector<resource_request *>& requests)
{
#ifndef NDEBUG
allocate_resources_contract_check
@ -158,10 +166,10 @@ namespace libtorrent {
{
// Resources are scarce
for(int i=0;i < (int)requests.size();i++)
for (int i = 0; i < (int)requests.size(); ++i)
requests[i]->given = 0;
if(resources == 0)
if (resources == 0)
return;
int resources_to_distribute =
@ -172,13 +180,17 @@ namespace libtorrent {
if (resources_to_distribute == 0)
return;
assert(resources_to_distribute>0);
assert(resources_to_distribute > 0);
std::random_shuffle(requests.begin(),requests.end());
std::sort(requests.begin(),requests.end(),by_used);
std::random_shuffle(requests.begin(), requests.end());
std::sort(requests.begin(), requests.end(), by_used);
while(resources_to_distribute > 0)
for(int i = 0; i < (int)requests.size() && resources_to_distribute>0; i++)
{
for(int i = 0;
i < (int)requests.size() && resources_to_distribute > 0;
++i)
{
resources_to_distribute -=
give(
requests[i],
@ -187,7 +199,9 @@ namespace libtorrent {
round_up_division(
(int)resources_to_distribute,
(int)requests.size()-i)));
}
}
assert(resources_to_distribute == 0);
}
}
}
}

View File

@ -1266,9 +1266,9 @@ namespace libtorrent
/*
size_type diff = share_diff();
enum { block_limit=2 }; // how many blocks difference is considered unfair
enum { block_limit = 2 }; // how many blocks difference is considered unfair
// if the peer has been choked, send tha current piece
// if the peer has been choked, send the current piece
// as fast as possible
if (diff > block_limit*m_torrent->block_size() || m_torrent->is_seed() || is_choked())
{

View File

@ -480,8 +480,9 @@ namespace libtorrent
boost::shared_ptr<peer_connection> c(
new peer_connection(*this, m_selector, s));
if (m_upload_rate != -1) {
c->upload_bandwidth.given=0;
if (m_upload_rate != -1)
{
c->upload_bandwidth.given = 0;
c->update_send_quota_left();
}
@ -636,8 +637,8 @@ namespace libtorrent
else if (i->second->should_request())
{
m_tracker_manager.queue_request(
i->second->generate_tracker_request(m_listen_port),
boost::get_pointer(i->second));
i->second->generate_tracker_request(m_listen_port)
, boost::get_pointer(i->second));
}
i->second->second_tick();
@ -647,10 +648,11 @@ namespace libtorrent
// distribute the maximum upload rate among the peers
control_upload_rates(m_upload_rate == -1
? std::numeric_limits<int>::max()
: m_upload_rate
,m_connections);
control_upload_rates(
m_upload_rate == -1
? std::numeric_limits<int>::max()
: m_upload_rate
, m_connections);
m_tracker_manager.tick();
@ -891,7 +893,7 @@ namespace libtorrent
= m_impl.m_connections.begin();
i != m_impl.m_connections.end();)
{
i->second->upload_bandwidth.given=std::numeric_limits<int>::max();
i->second->upload_bandwidth.given = std::numeric_limits<int>::max();
i->second->update_send_quota_left();
}
}