forked from premiere/premiere-libtorrent
*** empty log message ***
This commit is contained in:
parent
4cb125a694
commit
cea75e3723
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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,20 +100,25 @@ 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_)
|
||||
|
||||
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++)
|
||||
for (int i = 0; i < (int)requests.size(); ++i)
|
||||
{
|
||||
assert(requests[i]->used >= 0);
|
||||
assert(requests[i]->wanted >= 0);
|
||||
|
@ -124,7 +130,7 @@ namespace libtorrent {
|
|||
{
|
||||
int sum_given = 0;
|
||||
int sum_wanted = 0;
|
||||
for(int i=0;i<(int)requests.size();i++)
|
||||
for (int i = 0; i < (int)requests.size(); ++i)
|
||||
{
|
||||
assert(requests[i]->used >= 0);
|
||||
assert(requests[i]->wanted >= 0);
|
||||
|
@ -137,10 +143,12 @@ namespace libtorrent {
|
|||
assert(sum_given == std::min(resources,sum_wanted));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
void allocate_resources(int resources,
|
||||
std::vector<resource_request *> & requests)
|
||||
#endif
|
||||
} // namespace unnamed
|
||||
|
||||
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,6 +199,8 @@ namespace libtorrent {
|
|||
round_up_division(
|
||||
(int)resources_to_distribute,
|
||||
(int)requests.size()-i)));
|
||||
}
|
||||
}
|
||||
assert(resources_to_distribute == 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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
|
||||
control_upload_rates(
|
||||
m_upload_rate == -1
|
||||
? std::numeric_limits<int>::max()
|
||||
: m_upload_rate
|
||||
,m_connections);
|
||||
, 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue