forked from premiere/premiere-libtorrent
made libtorrent build on msvc-8 sp1
This commit is contained in:
parent
b626bd96d5
commit
4d04588def
|
@ -90,47 +90,47 @@ struct bandwidth_limit
|
||||||
{
|
{
|
||||||
static const int inf = boost::integer_traits<int>::const_max;
|
static const int inf = boost::integer_traits<int>::const_max;
|
||||||
|
|
||||||
bandwidth_limit()
|
bandwidth_limit() throw()
|
||||||
: m_quota_left(0)
|
: m_quota_left(0)
|
||||||
, m_local_limit(inf)
|
, m_local_limit(inf)
|
||||||
, m_current_rate(0)
|
, m_current_rate(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void throttle(int limit)
|
void throttle(int limit) throw()
|
||||||
{
|
{
|
||||||
m_local_limit = limit;
|
m_local_limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int throttle() const
|
int throttle() const throw()
|
||||||
{
|
{
|
||||||
return m_local_limit;
|
return m_local_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void assign(int amount)
|
void assign(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount > 0);
|
assert(amount > 0);
|
||||||
m_current_rate += amount;
|
m_current_rate += amount;
|
||||||
m_quota_left += amount;
|
m_quota_left += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_quota(int amount)
|
void use_quota(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount <= m_quota_left);
|
assert(amount <= m_quota_left);
|
||||||
m_quota_left -= amount;
|
m_quota_left -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quota_left() const
|
int quota_left() const throw()
|
||||||
{
|
{
|
||||||
return (std::max)(m_quota_left, 0);
|
return (std::max)(m_quota_left, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expire(int amount)
|
void expire(int amount) throw()
|
||||||
{
|
{
|
||||||
assert(amount >= 0);
|
assert(amount >= 0);
|
||||||
m_current_rate -= amount;
|
m_current_rate -= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_assignable() const
|
int max_assignable() const throw()
|
||||||
{
|
{
|
||||||
if (m_local_limit == inf) return inf;
|
if (m_local_limit == inf) return inf;
|
||||||
if (m_local_limit <= m_current_rate) return 0;
|
if (m_local_limit <= m_current_rate) return 0;
|
||||||
|
@ -160,7 +160,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
T clamp(T val, T ceiling, T floor)
|
T clamp(T val, T ceiling, T floor) throw()
|
||||||
{
|
{
|
||||||
assert(ceiling >= floor);
|
assert(ceiling >= floor);
|
||||||
if (val >= ceiling) return ceiling;
|
if (val >= ceiling) return ceiling;
|
||||||
|
@ -171,7 +171,7 @@ T clamp(T val, T ceiling, T floor)
|
||||||
template<class PeerConnection, class Torrent>
|
template<class PeerConnection, class Torrent>
|
||||||
struct bandwidth_manager
|
struct bandwidth_manager
|
||||||
{
|
{
|
||||||
bandwidth_manager(io_service& ios, int channel)
|
bandwidth_manager(io_service& ios, int channel) throw()
|
||||||
: m_ios(ios)
|
: m_ios(ios)
|
||||||
, m_history_timer(m_ios)
|
, m_history_timer(m_ios)
|
||||||
, m_limit(bandwidth_limit::inf)
|
, m_limit(bandwidth_limit::inf)
|
||||||
|
@ -179,14 +179,14 @@ struct bandwidth_manager
|
||||||
, m_channel(channel)
|
, m_channel(channel)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void throttle(int limit)
|
void throttle(int limit) throw()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
assert(limit >= 0);
|
assert(limit >= 0);
|
||||||
m_limit = limit;
|
m_limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
int throttle() const
|
int throttle() const throw()
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
return m_limit;
|
return m_limit;
|
||||||
|
@ -197,7 +197,7 @@ struct bandwidth_manager
|
||||||
// this is used by web seeds
|
// this is used by web seeds
|
||||||
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
void request_bandwidth(intrusive_ptr<PeerConnection> peer
|
||||||
, int blk
|
, int blk
|
||||||
, bool non_prioritized)
|
, bool non_prioritized) throw()
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
assert(blk > 0);
|
assert(blk > 0);
|
||||||
|
@ -257,8 +257,11 @@ struct bandwidth_manager
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void add_history_entry(history_entry<PeerConnection, Torrent> const& e) try
|
void add_history_entry(history_entry<PeerConnection, Torrent> const& e) throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
m_history.push_front(e);
|
m_history.push_front(e);
|
||||||
m_current_quota += e.amount;
|
m_current_quota += e.amount;
|
||||||
|
@ -268,11 +271,17 @@ private:
|
||||||
|
|
||||||
m_history_timer.expires_at(e.expires_at);
|
m_history_timer.expires_at(e.expires_at);
|
||||||
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
m_history_timer.async_wait(bind(&bandwidth_manager::on_history_expire, this, _1));
|
||||||
|
#ifndef NDEBUG
|
||||||
}
|
}
|
||||||
catch (std::exception&) { assert(false); }
|
catch (std::exception&) { assert(false); }
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void on_history_expire(asio::error_code const& e) try
|
void on_history_expire(asio::error_code const& e) throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
if (e) return;
|
if (e) return;
|
||||||
|
@ -303,14 +312,20 @@ private:
|
||||||
// means we can hand out more (in case there
|
// means we can hand out more (in case there
|
||||||
// are still consumers in line)
|
// are still consumers in line)
|
||||||
if (!m_queue.empty()) hand_out_bandwidth();
|
if (!m_queue.empty()) hand_out_bandwidth();
|
||||||
|
#ifndef NDEBUG
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
{
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
};
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void hand_out_bandwidth() try
|
void hand_out_bandwidth() throw()
|
||||||
{
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
try {
|
||||||
|
#endif
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
ptime now(time_now());
|
ptime now(time_now());
|
||||||
|
@ -404,9 +419,12 @@ private:
|
||||||
add_history_entry(history_entry<PeerConnection, Torrent>(
|
add_history_entry(history_entry<PeerConnection, Torrent>(
|
||||||
qe.peer, t, hand_out_amount, now + bw_window_size));
|
qe.peer, t, hand_out_amount, now + bw_window_size));
|
||||||
}
|
}
|
||||||
|
#ifndef NDEBUG
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{ assert(false); };
|
{ assert(false); };
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef boost::mutex mutex_t;
|
typedef boost::mutex mutex_t;
|
||||||
|
|
|
@ -197,16 +197,17 @@ namespace libtorrent { namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool on_extended(int length, int msg, buffer::const_interval body)
|
virtual bool on_extended(int length, int msg, buffer::const_interval body)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (msg != extension_index) return false;
|
if (msg != extension_index) return false;
|
||||||
if (m_message_index == 0) return false;
|
if (m_message_index == 0) return false;
|
||||||
|
|
||||||
if (length > 500 * 1024)
|
if (length > 500 * 1024)
|
||||||
throw protocol_error("ut peer exchange message larger than 500 kB");
|
throw protocol_error("uT peer exchange message larger than 500 kB");
|
||||||
|
|
||||||
if (body.left() < length) return true;
|
if (body.left() < length) return true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
entry pex_msg = bdecode(body.begin, body.end);
|
entry pex_msg = bdecode(body.begin, body.end);
|
||||||
std::string const& peers = pex_msg["added"].string();
|
std::string const& peers = pex_msg["added"].string();
|
||||||
std::string const& peer_flags = pex_msg["added.f"].string();
|
std::string const& peer_flags = pex_msg["added.f"].string();
|
||||||
|
@ -226,10 +227,11 @@ namespace libtorrent { namespace
|
||||||
char flags = detail::read_uint8(fin);
|
char flags = detail::read_uint8(fin);
|
||||||
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
p.peer_from_tracker(adr, pid, peer_info::pex, flags);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
{
|
{
|
||||||
|
throw protocol_error("invalid uT peer exchange message");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,13 @@ void test_transfer(bool clear_files = true, bool disconnect = false)
|
||||||
ses2.add_extension(&create_metadata_plugin);
|
ses2.add_extension(&create_metadata_plugin);
|
||||||
torrent_handle tor1;
|
torrent_handle tor1;
|
||||||
torrent_handle tor2;
|
torrent_handle tor2;
|
||||||
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
pe_settings pes;
|
pe_settings pes;
|
||||||
pes.out_enc_policy = pe_settings::disabled;
|
pes.out_enc_policy = pe_settings::disabled;
|
||||||
pes.in_enc_policy = pe_settings::disabled;
|
pes.in_enc_policy = pe_settings::disabled;
|
||||||
ses1.set_pe_settings(pes);
|
ses1.set_pe_settings(pes);
|
||||||
ses2.set_pe_settings(pes);
|
ses2.set_pe_settings(pes);
|
||||||
|
#endif
|
||||||
|
|
||||||
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, clear_files);
|
boost::tie(tor1, tor2, ignore) = setup_transfer(&ses1, &ses2, 0, clear_files);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue