2004-02-17 01:18:29 +01:00
|
|
|
/*
|
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
Copyright (c) 2003, Magnus Jonsson, Arvid Norberg
|
2004-02-17 01:18:29 +01:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2004-11-21 01:21:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
//The Standard Library defines the two template functions std::min()
|
|
|
|
//and std::max() in the <algorithm> header. In general, you should
|
|
|
|
//use these template functions for calculating the min and max values
|
|
|
|
//of a pair. Unfortunately, Visual C++ does not define these function
|
|
|
|
// templates. This is because the names min and max clash with
|
|
|
|
//the traditional min and max macros defined in <windows.h>.
|
|
|
|
//As a workaround, Visual C++ defines two alternative templates with
|
|
|
|
//identical functionality called _cpp_min() and _cpp_max(). You can
|
|
|
|
//use them instead of std::min() and std::max().To disable the
|
|
|
|
//generation of the min and max macros in Visual C++, #define
|
|
|
|
//NOMINMAX before #including <windows.h>.
|
2004-11-21 03:37:32 +01:00
|
|
|
|
2004-11-21 01:21:57 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
//support boost1.32.0(2004-11-19 18:47)
|
|
|
|
//now all libs can be compiled and linked with static module
|
|
|
|
#define NOMINMAX
|
|
|
|
#endif
|
2004-02-17 01:18:29 +01:00
|
|
|
|
|
|
|
#include "libtorrent/allocate_resources.hpp"
|
2004-02-24 20:23:37 +01:00
|
|
|
#include "libtorrent/size_type.hpp"
|
2004-03-22 15:56:32 +01:00
|
|
|
#include "libtorrent/peer_connection.hpp"
|
2004-03-23 23:58:18 +01:00
|
|
|
#include "libtorrent/torrent.hpp"
|
2004-03-22 15:56:32 +01:00
|
|
|
|
2004-02-17 01:18:29 +01:00
|
|
|
#include <cassert>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/limits.hpp>
|
|
|
|
|
2004-04-17 13:19:12 +02:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1310
|
2004-02-26 13:59:01 +01:00
|
|
|
#define for if (false) {} else for
|
2004-03-30 01:25:13 +02:00
|
|
|
#else
|
|
|
|
#include <boost/iterator/transform_iterator.hpp>
|
2004-02-26 13:59:01 +01:00
|
|
|
#endif
|
|
|
|
|
2004-02-24 13:45:05 +01:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
2004-03-23 23:58:18 +01:00
|
|
|
int saturated_add(int a, int b)
|
2004-02-17 01:18:29 +01:00
|
|
|
{
|
2004-03-23 23:58:18 +01:00
|
|
|
assert(a >= 0);
|
|
|
|
assert(b >= 0);
|
2006-04-25 23:04:48 +02:00
|
|
|
assert(a <= resource_request::inf);
|
|
|
|
assert(b <= resource_request::inf);
|
2005-08-23 11:59:56 +02:00
|
|
|
assert(resource_request::inf + resource_request::inf < 0);
|
2004-02-17 01:18:29 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
int sum = a + b;
|
2006-04-25 23:04:48 +02:00
|
|
|
if (sum < 0)
|
2005-08-23 11:59:56 +02:00
|
|
|
sum = resource_request::inf;
|
2004-02-17 01:18:29 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
assert(sum >= a && sum >= b);
|
|
|
|
return sum;
|
|
|
|
}
|
2004-02-23 23:54:54 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
namespace
|
|
|
|
{
|
2004-02-23 23:54:54 +01:00
|
|
|
// give num_resources to r,
|
|
|
|
// return how how many were actually accepted.
|
2004-03-22 15:56:32 +01:00
|
|
|
int give(resource_request& r, int num_resources)
|
2004-02-23 23:54:54 +01:00
|
|
|
{
|
2004-02-24 20:23:37 +01:00
|
|
|
assert(num_resources >= 0);
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(r.given <= r.max);
|
2004-02-23 23:54:54 +01:00
|
|
|
|
2004-03-27 23:02:31 +01:00
|
|
|
int accepted = std::min(num_resources, r.max - r.given);
|
2004-02-23 23:54:54 +01:00
|
|
|
assert(accepted >= 0);
|
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
r.given += accepted;
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(r.given <= r.max);
|
2004-02-23 23:54:54 +01:00
|
|
|
|
|
|
|
return accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2004-02-24 13:45:05 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
template<class It, class T>
|
2004-02-24 13:45:05 +01:00
|
|
|
class allocate_resources_contract_check
|
2004-02-23 23:54:54 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
int m_resources;
|
|
|
|
It m_start;
|
|
|
|
It m_end;
|
|
|
|
resource_request T::* m_res;
|
2004-02-24 13:45:05 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
allocate_resources_contract_check(
|
2004-03-22 15:56:32 +01:00
|
|
|
int resources
|
|
|
|
, It start
|
|
|
|
, It end
|
|
|
|
, resource_request T::* res)
|
|
|
|
: m_resources(resources)
|
|
|
|
, m_start(start)
|
|
|
|
, m_end(end)
|
|
|
|
, m_res(res)
|
2004-02-23 23:54:54 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
assert(m_resources >= 0);
|
|
|
|
for (It i = m_start, end(m_end); i != end; ++i)
|
2004-02-24 13:45:05 +01:00
|
|
|
{
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(((*i).*m_res).max >= 0);
|
2004-03-22 15:56:32 +01:00
|
|
|
assert(((*i).*m_res).given >= 0);
|
2004-02-24 13:45:05 +01:00
|
|
|
}
|
2004-02-23 23:54:54 +01:00
|
|
|
}
|
|
|
|
|
2004-02-24 13:45:05 +01:00
|
|
|
~allocate_resources_contract_check()
|
2004-02-23 23:54:54 +01:00
|
|
|
{
|
2004-02-24 13:45:05 +01:00
|
|
|
int sum_given = 0;
|
2004-03-27 23:02:31 +01:00
|
|
|
int sum_max = 0;
|
2004-10-29 15:21:09 +02:00
|
|
|
int sum_min = 0;
|
2004-03-22 15:56:32 +01:00
|
|
|
for (It i = m_start, end(m_end); i != end; ++i)
|
2004-02-24 13:45:05 +01:00
|
|
|
{
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(((*i).*m_res).max >= 0);
|
2004-10-29 15:21:09 +02:00
|
|
|
assert(((*i).*m_res).min >= 0);
|
|
|
|
assert(((*i).*m_res).max >= ((*i).*m_res).min);
|
2004-03-22 15:56:32 +01:00
|
|
|
assert(((*i).*m_res).given >= 0);
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(((*i).*m_res).given <= ((*i).*m_res).max);
|
2004-02-24 13:45:05 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
sum_given = saturated_add(sum_given, ((*i).*m_res).given);
|
2004-03-27 23:02:31 +01:00
|
|
|
sum_max = saturated_add(sum_max, ((*i).*m_res).max);
|
2004-10-29 15:21:09 +02:00
|
|
|
sum_min = saturated_add(sum_min, ((*i).*m_res).min);
|
2004-02-24 13:45:05 +01:00
|
|
|
}
|
2004-10-29 15:21:09 +02:00
|
|
|
assert(sum_given == std::min(std::max(m_resources, sum_min), sum_max));
|
2004-02-23 23:54:54 +01:00
|
|
|
}
|
2004-02-24 13:45:05 +01:00
|
|
|
};
|
|
|
|
|
2004-02-23 23:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
template<class It, class T>
|
|
|
|
void allocate_resources_impl(
|
|
|
|
int resources
|
|
|
|
, It start
|
|
|
|
, It end
|
|
|
|
, resource_request T::* res)
|
2004-02-17 01:18:29 +01:00
|
|
|
{
|
2006-08-10 21:18:11 +02:00
|
|
|
assert(resources >= 0);
|
2004-03-22 15:56:32 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
allocate_resources_contract_check<It, T> contract_check(
|
|
|
|
resources
|
|
|
|
, start
|
|
|
|
, end
|
|
|
|
, res);
|
|
|
|
#endif
|
|
|
|
|
2006-04-25 23:04:48 +02:00
|
|
|
if (resources == resource_request::inf)
|
2004-03-22 15:56:32 +01:00
|
|
|
{
|
|
|
|
// No competition for resources.
|
|
|
|
// Just give everyone what they want.
|
|
|
|
for (It i = start; i != end; ++i)
|
|
|
|
{
|
2004-03-27 23:02:31 +01:00
|
|
|
((*i).*res).given = ((*i).*res).max;
|
2004-03-22 15:56:32 +01:00
|
|
|
}
|
2004-02-23 23:54:54 +01:00
|
|
|
return;
|
2004-03-22 15:56:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resources are scarce
|
2004-02-23 23:54:54 +01:00
|
|
|
|
2004-03-27 23:02:31 +01:00
|
|
|
int sum_max = 0;
|
|
|
|
int sum_min = 0;
|
2004-03-22 15:56:32 +01:00
|
|
|
for (It i = start; i != end; ++i)
|
|
|
|
{
|
2004-03-27 23:02:31 +01:00
|
|
|
sum_max = saturated_add(sum_max, ((*i).*res).max);
|
2005-08-23 11:59:56 +02:00
|
|
|
assert(((*i).*res).min < resource_request::inf);
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(((*i).*res).min >= 0);
|
|
|
|
assert(((*i).*res).min <= ((*i).*res).max);
|
|
|
|
sum_min += ((*i).*res).min;
|
|
|
|
((*i).*res).given = ((*i).*res).min;
|
2004-03-22 15:56:32 +01:00
|
|
|
}
|
2004-02-17 01:18:29 +01:00
|
|
|
|
2004-03-27 23:02:31 +01:00
|
|
|
if (resources == 0 || sum_max == 0)
|
2004-02-23 23:54:54 +01:00
|
|
|
return;
|
|
|
|
|
2004-10-29 15:21:09 +02:00
|
|
|
resources = std::max(resources, sum_min);
|
2004-03-27 23:02:31 +01:00
|
|
|
int resources_to_distribute = std::min(resources, sum_max) - sum_min;
|
|
|
|
assert(resources_to_distribute >= 0);
|
2006-08-10 21:18:11 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
int prev_resources_to_distribute = resources_to_distribute;
|
|
|
|
#endif
|
2004-03-22 15:56:32 +01:00
|
|
|
while (resources_to_distribute > 0)
|
2004-02-24 13:45:05 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
size_type total_used = 0;
|
|
|
|
size_type max_used = 0;
|
|
|
|
for (It i = start; i != end; ++i)
|
2004-02-24 20:23:37 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
resource_request& r = (*i).*res;
|
2004-03-27 23:02:31 +01:00
|
|
|
if(r.given == r.max) continue;
|
2004-02-24 20:23:37 +01:00
|
|
|
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(r.given < r.max);
|
2004-02-24 20:23:37 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
max_used = std::max(max_used, (size_type)r.used + 1);
|
|
|
|
total_used += (size_type)r.used + 1;
|
2004-02-24 13:45:05 +01:00
|
|
|
}
|
2004-02-24 20:23:37 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
size_type kNumer = resources_to_distribute;
|
|
|
|
size_type kDenom = total_used;
|
2006-08-10 21:18:11 +02:00
|
|
|
assert(kNumer >= 0);
|
|
|
|
assert(kDenom >= 0);
|
|
|
|
assert(kNumer <= std::numeric_limits<int>::max());
|
|
|
|
assert(total_used < std::numeric_limits<int>::max());
|
2004-02-24 20:23:37 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
if (kNumer * max_used <= kDenom)
|
2004-02-24 20:23:37 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
kNumer = 1;
|
|
|
|
kDenom = max_used;
|
2006-08-10 21:18:11 +02:00
|
|
|
assert(kDenom >= 0);
|
|
|
|
assert(kDenom <= std::numeric_limits<int>::max());
|
2004-02-24 20:23:37 +01:00
|
|
|
}
|
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
for (It i = start; i != end && resources_to_distribute > 0; ++i)
|
2004-02-25 00:48:02 +01:00
|
|
|
{
|
2004-03-22 15:56:32 +01:00
|
|
|
resource_request& r = (*i).*res;
|
2006-04-25 23:04:48 +02:00
|
|
|
if (r.given == r.max) continue;
|
2004-02-25 00:48:02 +01:00
|
|
|
|
2004-03-27 23:02:31 +01:00
|
|
|
assert(r.given < r.max);
|
2004-02-25 00:48:02 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
size_type used = (size_type)r.used + 1;
|
2006-04-25 23:04:48 +02:00
|
|
|
if (used < 1) used = 1;
|
2005-08-23 11:59:56 +02:00
|
|
|
size_type to_give = used * kNumer / kDenom;
|
2006-08-06 18:36:00 +02:00
|
|
|
if (to_give > resources_to_distribute)
|
|
|
|
to_give = resources_to_distribute;
|
2006-04-25 23:04:48 +02:00
|
|
|
assert(to_give >= 0);
|
2006-08-06 18:36:00 +02:00
|
|
|
assert(to_give <= resources_to_distribute);
|
2005-08-23 11:59:56 +02:00
|
|
|
resources_to_distribute -= give(r, (int)to_give);
|
2006-04-25 23:04:48 +02:00
|
|
|
assert(resources_to_distribute >= 0);
|
2004-02-25 00:48:02 +01:00
|
|
|
}
|
2004-03-22 15:56:32 +01:00
|
|
|
|
2004-02-24 20:23:37 +01:00
|
|
|
assert(resources_to_distribute >= 0);
|
2006-08-10 21:18:11 +02:00
|
|
|
assert(resources_to_distribute < prev_resources_to_distribute);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
prev_resources_to_distribute = resources_to_distribute;
|
|
|
|
#endif
|
2004-02-24 13:45:05 +01:00
|
|
|
}
|
2004-03-22 15:56:32 +01:00
|
|
|
}
|
2004-02-24 20:23:37 +01:00
|
|
|
|
2004-03-22 15:56:32 +01:00
|
|
|
peer_connection& pick_peer(
|
2006-04-25 23:04:48 +02:00
|
|
|
std::pair<boost::shared_ptr<stream_socket>
|
|
|
|
, boost::intrusive_ptr<peer_connection> > const& p)
|
2004-03-22 15:56:32 +01:00
|
|
|
{
|
|
|
|
return *p.second;
|
2004-02-17 01:18:29 +01:00
|
|
|
}
|
2004-03-22 15:56:32 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
peer_connection& pick_peer2(
|
2006-04-25 23:04:48 +02:00
|
|
|
std::pair<tcp::endpoint, peer_connection*> const& p)
|
2004-03-23 23:58:18 +01:00
|
|
|
{
|
|
|
|
return *p.second;
|
|
|
|
}
|
2004-03-22 15:56:32 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
torrent& deref(std::pair<sha1_hash, boost::shared_ptr<torrent> > const& p)
|
|
|
|
{
|
|
|
|
return *p.second;
|
|
|
|
}
|
2004-03-22 15:56:32 +01:00
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
|
|
|
|
} // namespace anonymous
|
|
|
|
|
|
|
|
/*
|
2004-03-22 15:56:32 +01:00
|
|
|
void allocate_resources(
|
|
|
|
int resources
|
2006-04-25 23:04:48 +02:00
|
|
|
, std::map<boost::shared_ptr<socket>, boost::intrusive_ptr<peer_connection> >& c
|
2004-03-22 15:56:32 +01:00
|
|
|
, resource_request peer_connection::* res)
|
|
|
|
{
|
2006-04-25 23:04:48 +02:00
|
|
|
typedef std::map<boost::shared_ptr<socket>, boost::intrusive_ptr<peer_connection> >::iterator orig_iter;
|
|
|
|
typedef std::pair<boost::shared_ptr<socket>, boost::intrusive_ptr<peer_connection> > in_param;
|
2004-03-22 15:56:32 +01:00
|
|
|
typedef boost::transform_iterator<peer_connection& (*)(in_param const&), orig_iter> new_iter;
|
|
|
|
|
|
|
|
allocate_resources_impl(
|
|
|
|
resources
|
|
|
|
, new_iter(c.begin(), &pick_peer)
|
|
|
|
, new_iter(c.end(), &pick_peer)
|
|
|
|
, res);
|
2004-02-17 01:18:29 +01:00
|
|
|
}
|
2004-03-23 23:58:18 +01:00
|
|
|
*/
|
2004-04-17 13:19:12 +02:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER < 1310
|
2004-03-30 01:25:13 +02:00
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
struct iterator_wrapper
|
|
|
|
{
|
|
|
|
typedef std::map<sha1_hash, boost::shared_ptr<torrent> >::iterator orig_iter;
|
|
|
|
|
|
|
|
orig_iter iter;
|
|
|
|
|
|
|
|
iterator_wrapper(orig_iter i): iter(i) {}
|
|
|
|
void operator++() { ++iter; }
|
|
|
|
torrent& operator*() { return *(iter->second); }
|
|
|
|
bool operator==(const iterator_wrapper& i) const
|
|
|
|
{ return iter == i.iter; }
|
|
|
|
bool operator!=(const iterator_wrapper& i) const
|
|
|
|
{ return iter != i.iter; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iterator_wrapper2
|
|
|
|
{
|
2006-04-25 23:04:48 +02:00
|
|
|
typedef std::map<tcp::endpoint, peer_connection*>::iterator orig_iter;
|
2004-03-30 01:25:13 +02:00
|
|
|
|
|
|
|
orig_iter iter;
|
|
|
|
|
|
|
|
iterator_wrapper2(orig_iter i): iter(i) {}
|
|
|
|
void operator++() { ++iter; }
|
|
|
|
peer_connection& operator*() { return *(iter->second); }
|
|
|
|
bool operator==(const iterator_wrapper2& i) const
|
|
|
|
{ return iter == i.iter; }
|
|
|
|
bool operator!=(const iterator_wrapper2& i) const
|
|
|
|
{ return iter != i.iter; }
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void allocate_resources(
|
|
|
|
int resources
|
|
|
|
, std::map<sha1_hash, boost::shared_ptr<torrent> >& c
|
|
|
|
, resource_request torrent::* res)
|
|
|
|
{
|
|
|
|
allocate_resources_impl(
|
|
|
|
resources
|
|
|
|
, detail::iterator_wrapper(c.begin())
|
|
|
|
, detail::iterator_wrapper(c.end())
|
|
|
|
, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void allocate_resources(
|
|
|
|
int resources
|
2006-04-25 23:04:48 +02:00
|
|
|
, std::map<tcp::endpoint, peer_connection*>& c
|
2004-03-30 01:25:13 +02:00
|
|
|
, resource_request peer_connection::* res)
|
|
|
|
{
|
|
|
|
allocate_resources_impl(
|
|
|
|
resources
|
|
|
|
, detail::iterator_wrapper2(c.begin())
|
|
|
|
, detail::iterator_wrapper2(c.end())
|
|
|
|
, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2004-03-23 23:58:18 +01:00
|
|
|
void allocate_resources(
|
|
|
|
int resources
|
|
|
|
, std::map<sha1_hash, boost::shared_ptr<torrent> >& c
|
|
|
|
, resource_request torrent::* res)
|
|
|
|
{
|
|
|
|
typedef std::map<sha1_hash, boost::shared_ptr<torrent> >::iterator orig_iter;
|
|
|
|
typedef std::pair<sha1_hash, boost::shared_ptr<torrent> > in_param;
|
|
|
|
typedef boost::transform_iterator<torrent& (*)(in_param const&), orig_iter> new_iter;
|
|
|
|
|
|
|
|
allocate_resources_impl(
|
|
|
|
resources
|
|
|
|
, new_iter(c.begin(), &deref)
|
|
|
|
, new_iter(c.end(), &deref)
|
|
|
|
, res);
|
|
|
|
}
|
|
|
|
|
|
|
|
void allocate_resources(
|
|
|
|
int resources
|
2006-04-25 23:04:48 +02:00
|
|
|
, std::map<tcp::endpoint, peer_connection*>& c
|
2004-03-23 23:58:18 +01:00
|
|
|
, resource_request peer_connection::* res)
|
|
|
|
{
|
2006-04-25 23:04:48 +02:00
|
|
|
typedef std::map<tcp::endpoint, peer_connection*>::iterator orig_iter;
|
|
|
|
typedef std::pair<tcp::endpoint, peer_connection*> in_param;
|
2004-03-23 23:58:18 +01:00
|
|
|
typedef boost::transform_iterator<peer_connection& (*)(in_param const&), orig_iter> new_iter;
|
|
|
|
|
|
|
|
allocate_resources_impl(
|
|
|
|
resources
|
|
|
|
, new_iter(c.begin(), &pick_peer2)
|
|
|
|
, new_iter(c.end(), &pick_peer2)
|
|
|
|
, res);
|
|
|
|
}
|
2004-03-30 01:25:13 +02:00
|
|
|
#endif
|
2004-03-22 15:56:32 +01:00
|
|
|
|
|
|
|
} // namespace libtorrent
|