loop conversions. replace unsafe "erase(iter++)" with "iter = erase(iter)"
This commit is contained in:
parent
94effa6ba7
commit
713c412682
|
@ -781,7 +781,7 @@ void scan_dir(std::string const& dir_path
|
||||||
torrent_handle& h = i->second;
|
torrent_handle& h = i->second;
|
||||||
if (!h.is_valid())
|
if (!h.is_valid())
|
||||||
{
|
{
|
||||||
files.erase(i++);
|
i = files.erase(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -792,7 +792,7 @@ void scan_dir(std::string const& dir_path
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
++num_outstanding_resume_data;
|
++num_outstanding_resume_data;
|
||||||
|
|
||||||
files.erase(i++);
|
i = files.erase(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -239,16 +239,14 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_mutex);
|
std::unique_lock<std::mutex> l(m_mutex);
|
||||||
|
|
||||||
auto begin = m_files.lower_bound(std::make_pair(st, file_index_t(0)));
|
auto const begin = m_files.lower_bound(std::make_pair(st, file_index_t(0)));
|
||||||
auto const end = m_files.upper_bound(std::make_pair(st
|
auto const end = m_files.upper_bound(std::make_pair(st
|
||||||
, std::numeric_limits<file_index_t>::max()));
|
, std::numeric_limits<file_index_t>::max()));
|
||||||
|
|
||||||
std::vector<file_handle> to_close;
|
std::vector<file_handle> to_close;
|
||||||
while (begin != end)
|
for (auto it = begin; it != end; ++it)
|
||||||
{
|
to_close.push_back(std::move(it->second.file_ptr));
|
||||||
to_close.push_back(std::move(begin->second.file_ptr));
|
if (!to_close.empty()) m_files.erase(begin, end);
|
||||||
m_files.erase(begin++);
|
|
||||||
}
|
|
||||||
l.unlock();
|
l.unlock();
|
||||||
// the files are closed here while the lock is not held
|
// the files are closed here while the lock is not held
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,7 +497,7 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no more peers, remove the entry altogether
|
// if there are no more peers, remove the entry altogether
|
||||||
m_map.erase(i++);
|
i = m_map.erase(i);
|
||||||
m_counters.torrents -= 1;// peers is decreased by purge_peers
|
m_counters.torrents -= 1;// peers is decreased by purge_peers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,7 +515,7 @@ namespace
|
||||||
++i;
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m_immutable_table.erase(i++);
|
i = m_immutable_table.erase(i);
|
||||||
m_counters.immutable_data -= 1;
|
m_counters.immutable_data -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ namespace
|
||||||
++i;
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
m_mutable_table.erase(i++);
|
i = m_mutable_table.erase(i);
|
||||||
m_counters.mutable_data -= 1;
|
m_counters.mutable_data -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -403,7 +403,7 @@ time_duration rpc_manager::tick()
|
||||||
, print_endpoint(o->target_ep()).c_str());
|
, print_endpoint(o->target_ep()).c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_transactions.erase(i++);
|
i = m_transactions.erase(i);
|
||||||
timeouts.push_back(o);
|
timeouts.push_back(o);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1022,9 +1022,8 @@ namespace aux {
|
||||||
|
|
||||||
// Close connections whose endpoint is filtered
|
// Close connections whose endpoint is filtered
|
||||||
// by the new ip-filter
|
// by the new ip-filter
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
i.second->set_ip_filter(m_ip_filter);
|
||||||
i->second->set_ip_filter(m_ip_filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_impl::ban_ip(address addr)
|
void session_impl::ban_ip(address addr)
|
||||||
|
@ -1032,9 +1031,8 @@ namespace aux {
|
||||||
TORRENT_ASSERT(is_single_thread());
|
TORRENT_ASSERT(is_single_thread());
|
||||||
if (!m_ip_filter) m_ip_filter = std::make_shared<ip_filter>();
|
if (!m_ip_filter) m_ip_filter = std::make_shared<ip_filter>();
|
||||||
m_ip_filter->add_rule(addr, addr, ip_filter::blocked);
|
m_ip_filter->add_rule(addr, addr, ip_filter::blocked);
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
i.second->set_ip_filter(m_ip_filter);
|
||||||
i->second->set_ip_filter(m_ip_filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_filter const& session_impl::get_ip_filter()
|
ip_filter const& session_impl::get_ip_filter()
|
||||||
|
@ -1367,11 +1365,10 @@ namespace aux {
|
||||||
tcp::endpoint session_impl::get_ipv6_interface() const
|
tcp::endpoint session_impl::get_ipv6_interface() const
|
||||||
{
|
{
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
for (std::list<listen_socket_t>::const_iterator i = m_listen_sockets.begin()
|
for (auto const& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (!i->local_endpoint.address().is_v6()) continue;
|
if (!i.local_endpoint.address().is_v6()) continue;
|
||||||
return tcp::endpoint(i->local_endpoint.address(), std::uint16_t(i->tcp_external_port));
|
return tcp::endpoint(i.local_endpoint.address(), std::uint16_t(i.tcp_external_port));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return tcp::endpoint();
|
return tcp::endpoint();
|
||||||
|
@ -1379,11 +1376,10 @@ namespace aux {
|
||||||
|
|
||||||
tcp::endpoint session_impl::get_ipv4_interface() const
|
tcp::endpoint session_impl::get_ipv4_interface() const
|
||||||
{
|
{
|
||||||
for (std::list<listen_socket_t>::const_iterator i = m_listen_sockets.begin()
|
for (auto const& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (!i->local_endpoint.address().is_v4()) continue;
|
if (!i.local_endpoint.address().is_v4()) continue;
|
||||||
return tcp::endpoint(i->local_endpoint.address(), std::uint16_t(i->tcp_external_port));
|
return tcp::endpoint(i.local_endpoint.address(), std::uint16_t(i.tcp_external_port));
|
||||||
}
|
}
|
||||||
return tcp::endpoint();
|
return tcp::endpoint();
|
||||||
}
|
}
|
||||||
|
@ -2176,22 +2172,21 @@ namespace aux {
|
||||||
// for now, just pick the first socket with a matching address family
|
// for now, just pick the first socket with a matching address family
|
||||||
// TODO: 3 for proper multi-homed support, we may want to do something
|
// TODO: 3 for proper multi-homed support, we may want to do something
|
||||||
// else here. Probably let the caller decide which interface to send over
|
// else here. Probably let the caller decide which interface to send over
|
||||||
for (std::list<listen_socket_t>::iterator i = m_listen_sockets.begin()
|
for (auto& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (!i->udp_sock) continue;
|
if (!i.udp_sock) continue;
|
||||||
if (i->ssl) continue;
|
if (i.ssl) continue;
|
||||||
|
|
||||||
i->udp_sock->send_hostname(hostname, port, p, ec, flags);
|
i.udp_sock->send_hostname(hostname, port, p, ec, flags);
|
||||||
|
|
||||||
if ((ec == error::would_block
|
if ((ec == error::would_block
|
||||||
|| ec == error::try_again)
|
|| ec == error::try_again)
|
||||||
&& !i->udp_write_blocked)
|
&& !i.udp_write_blocked)
|
||||||
{
|
{
|
||||||
i->udp_write_blocked = true;
|
i.udp_write_blocked = true;
|
||||||
ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable");
|
ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable");
|
||||||
i->udp_sock->async_write(std::bind(&session_impl::on_udp_writeable
|
i.udp_sock->async_write(std::bind(&session_impl::on_udp_writeable
|
||||||
, this, std::weak_ptr<udp_socket>(i->udp_sock), _1));
|
, this, std::weak_ptr<udp_socket>(i.udp_sock), _1));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2207,24 +2202,23 @@ namespace aux {
|
||||||
// for now, just pick the first socket with a matching address family
|
// for now, just pick the first socket with a matching address family
|
||||||
// TODO: 3 for proper multi-homed support, we may want to do something
|
// TODO: 3 for proper multi-homed support, we may want to do something
|
||||||
// else here. Probably let the caller decide which interface to send over
|
// else here. Probably let the caller decide which interface to send over
|
||||||
for (std::list<listen_socket_t>::iterator i = m_listen_sockets.begin()
|
for (auto& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (i->ssl != ssl) continue;
|
if (i.ssl != ssl) continue;
|
||||||
if (!i->udp_sock) continue;
|
if (!i.udp_sock) continue;
|
||||||
if (i->local_endpoint.address().is_v4() != ep.address().is_v4())
|
if (i.local_endpoint.address().is_v4() != ep.address().is_v4())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
i->udp_sock->send(ep, p, ec, flags);
|
i.udp_sock->send(ep, p, ec, flags);
|
||||||
|
|
||||||
if ((ec == error::would_block
|
if ((ec == error::would_block
|
||||||
|| ec == error::try_again)
|
|| ec == error::try_again)
|
||||||
&& !i->udp_write_blocked)
|
&& !i.udp_write_blocked)
|
||||||
{
|
{
|
||||||
i->udp_write_blocked = true;
|
i.udp_write_blocked = true;
|
||||||
ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable");
|
ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable");
|
||||||
i->udp_sock->async_write(std::bind(&session_impl::on_udp_writeable
|
i.udp_sock->async_write(std::bind(&session_impl::on_udp_writeable
|
||||||
, this, std::weak_ptr<udp_socket>(i->udp_sock), _1));
|
, this, std::weak_ptr<udp_socket>(i.udp_sock), _1));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2796,10 +2790,9 @@ namespace aux {
|
||||||
if (!m_settings.get_bool(settings_pack::incoming_starts_queued_torrents))
|
if (!m_settings.get_bool(settings_pack::incoming_starts_queued_torrents))
|
||||||
{
|
{
|
||||||
bool has_active_torrent = false;
|
bool has_active_torrent = false;
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (!i->second->is_torrent_paused())
|
if (!i.second->is_torrent_paused())
|
||||||
{
|
{
|
||||||
has_active_torrent = true;
|
has_active_torrent = true;
|
||||||
break;
|
break;
|
||||||
|
@ -3146,10 +3139,9 @@ namespace aux {
|
||||||
m_created += hours(4);
|
m_created += hours(4);
|
||||||
|
|
||||||
const int four_hours = 60 * 60 * 4;
|
const int four_hours = 60 * 60 * 4;
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
i->second->step_session_time(four_hours);
|
i.second->step_session_time(four_hours);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3617,11 +3609,8 @@ namespace aux {
|
||||||
void session_impl::auto_manage_checking_torrents(std::vector<torrent*>& list
|
void session_impl::auto_manage_checking_torrents(std::vector<torrent*>& list
|
||||||
, int& limit)
|
, int& limit)
|
||||||
{
|
{
|
||||||
for (std::vector<torrent*>::iterator i = list.begin()
|
for (auto& t : list)
|
||||||
, end(list.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = *i;
|
|
||||||
|
|
||||||
TORRENT_ASSERT(t->state() == torrent_status::checking_files);
|
TORRENT_ASSERT(t->state() == torrent_status::checking_files);
|
||||||
TORRENT_ASSERT(t->is_auto_managed());
|
TORRENT_ASSERT(t->is_auto_managed());
|
||||||
if (limit <= 0)
|
if (limit <= 0)
|
||||||
|
@ -3641,11 +3630,8 @@ namespace aux {
|
||||||
, int& dht_limit, int& tracker_limit
|
, int& dht_limit, int& tracker_limit
|
||||||
, int& lsd_limit, int& hard_limit, int type_limit)
|
, int& lsd_limit, int& hard_limit, int type_limit)
|
||||||
{
|
{
|
||||||
for (std::vector<torrent*>::iterator i = list.begin()
|
for (auto& t : list)
|
||||||
, end(list.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = *i;
|
|
||||||
|
|
||||||
TORRENT_ASSERT(t->state() != torrent_status::checking_files);
|
TORRENT_ASSERT(t->state() != torrent_status::checking_files);
|
||||||
|
|
||||||
// inactive torrents don't count (and if you configured them to do so,
|
// inactive torrents don't count (and if you configured them to do so,
|
||||||
|
@ -4307,10 +4293,9 @@ namespace aux {
|
||||||
// torrent pointers. Maybe this logic could be simplified
|
// torrent pointers. Maybe this logic could be simplified
|
||||||
if (p >= 0 && me->queue_position() == -1)
|
if (p >= 0 && me->queue_position() == -1)
|
||||||
{
|
{
|
||||||
for (session_impl::torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = i->second.get();
|
torrent* t = i.second.get();
|
||||||
if (t->queue_position() >= p)
|
if (t->queue_position() >= p)
|
||||||
{
|
{
|
||||||
t->set_queue_position_impl(t->queue_position()+1);
|
t->set_queue_position_impl(t->queue_position()+1);
|
||||||
|
@ -4325,10 +4310,9 @@ namespace aux {
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(me->queue_position() >= 0);
|
TORRENT_ASSERT(me->queue_position() >= 0);
|
||||||
TORRENT_ASSERT(p == -1);
|
TORRENT_ASSERT(p == -1);
|
||||||
for (session_impl::torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = i->second.get();
|
torrent* t = i.second.get();
|
||||||
if (t == me) continue;
|
if (t == me) continue;
|
||||||
if (t->queue_position() == -1) continue;
|
if (t->queue_position() == -1) continue;
|
||||||
if (t->queue_position() >= me->queue_position())
|
if (t->queue_position() >= me->queue_position())
|
||||||
|
@ -4342,10 +4326,9 @@ namespace aux {
|
||||||
}
|
}
|
||||||
else if (p < me->queue_position())
|
else if (p < me->queue_position())
|
||||||
{
|
{
|
||||||
for (session_impl::torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = i->second.get();
|
torrent* t = i.second.get();
|
||||||
if (t == me) continue;
|
if (t == me) continue;
|
||||||
if (t->queue_position() == -1) continue;
|
if (t->queue_position() == -1) continue;
|
||||||
if (t->queue_position() >= p
|
if (t->queue_position() >= p
|
||||||
|
@ -4359,10 +4342,9 @@ namespace aux {
|
||||||
}
|
}
|
||||||
else if (p > me->queue_position())
|
else if (p > me->queue_position())
|
||||||
{
|
{
|
||||||
for (session_impl::torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
torrent* t = i->second.get();
|
torrent* t = i.second.get();
|
||||||
int pos = t->queue_position();
|
int pos = t->queue_position();
|
||||||
if (t == me) continue;
|
if (t == me) continue;
|
||||||
if (pos == -1) continue;
|
if (pos == -1) continue;
|
||||||
|
@ -4580,12 +4562,10 @@ namespace aux {
|
||||||
{
|
{
|
||||||
std::vector<torrent_handle> ret;
|
std::vector<torrent_handle> ret;
|
||||||
|
|
||||||
for (torrent_map::const_iterator i
|
for (auto const& i : m_torrents)
|
||||||
= m_torrents.begin(), end(m_torrents.end());
|
|
||||||
i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (i->second->is_aborted()) continue;
|
if (i.second->is_aborted()) continue;
|
||||||
ret.push_back(torrent_handle(i->second));
|
ret.push_back(torrent_handle(i.second));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -5165,18 +5145,14 @@ namespace aux {
|
||||||
|
|
||||||
void session_impl::update_auto_sequential()
|
void session_impl::update_auto_sequential()
|
||||||
{
|
{
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
i.second->update_auto_sequential();
|
||||||
i->second->update_auto_sequential();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_impl::update_max_failcount()
|
void session_impl::update_max_failcount()
|
||||||
{
|
{
|
||||||
for (torrent_map::iterator i = m_torrents.begin()
|
for (auto& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
i.second->update_max_failcount();
|
||||||
{
|
|
||||||
i->second->update_max_failcount();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_impl::update_close_file_interval()
|
void session_impl::update_close_file_interval()
|
||||||
|
@ -5197,10 +5173,9 @@ namespace aux {
|
||||||
// in case we just set a socks proxy, we might have to
|
// in case we just set a socks proxy, we might have to
|
||||||
// open the socks incoming connection
|
// open the socks incoming connection
|
||||||
if (!m_socks_listen_socket) open_new_incoming_socks_connection();
|
if (!m_socks_listen_socket) open_new_incoming_socks_connection();
|
||||||
for (std::list<listen_socket_t>::iterator i = m_listen_sockets.begin()
|
for (auto& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
i->udp_sock->set_proxy_settings(proxy());
|
i.udp_sock->set_proxy_settings(proxy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5523,10 +5498,9 @@ namespace aux {
|
||||||
// this loop is potentially expensive. It could be optimized by
|
// this loop is potentially expensive. It could be optimized by
|
||||||
// simply keeping a global counter
|
// simply keeping a global counter
|
||||||
int peerlist_size = 0;
|
int peerlist_size = 0;
|
||||||
for (torrent_map::const_iterator i = m_torrents.begin()
|
for (auto const& i : m_torrents)
|
||||||
, end(m_torrents.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
peerlist_size += i->second->num_known_peers();
|
peerlist_size += i.second->num_known_peers();
|
||||||
}
|
}
|
||||||
|
|
||||||
s.peerlist_size = peerlist_size;
|
s.peerlist_size = peerlist_size;
|
||||||
|
@ -6236,17 +6210,16 @@ namespace aux {
|
||||||
|
|
||||||
void session_impl::update_force_proxy()
|
void session_impl::update_force_proxy()
|
||||||
{
|
{
|
||||||
for (std::list<listen_socket_t>::iterator i = m_listen_sockets.begin()
|
for (auto& i : m_listen_sockets)
|
||||||
, end(m_listen_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
i->udp_sock->set_force_proxy(m_settings.get_bool(settings_pack::force_proxy));
|
i.udp_sock->set_force_proxy(m_settings.get_bool(settings_pack::force_proxy));
|
||||||
|
|
||||||
// close the TCP listen sockets
|
// close the TCP listen sockets
|
||||||
if (i->sock)
|
if (i.sock)
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
i->sock->close(ec);
|
i.sock->close(ec);
|
||||||
i->sock.reset();
|
i.sock.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6769,10 +6742,9 @@ namespace aux {
|
||||||
for (int l = 0; l < num_torrent_lists; ++l)
|
for (int l = 0; l < num_torrent_lists; ++l)
|
||||||
{
|
{
|
||||||
std::vector<torrent*> const& list = m_torrent_lists[l];
|
std::vector<torrent*> const& list = m_torrent_lists[l];
|
||||||
for (std::vector<torrent*>::const_iterator i = list.begin()
|
for (auto const& i : list)
|
||||||
, end(list.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT((*i)->m_links[l].in_list());
|
TORRENT_ASSERT(i->m_links[l].in_list());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace
|
||||||
, r, std::bind(&smart_ban_plugin::on_read_ok_block
|
, r, std::bind(&smart_ban_plugin::on_read_ok_block
|
||||||
, shared_from_this(), *i, i->second.peer->address(), _1, r.length, _2, _3)
|
, shared_from_this(), *i, i->second.peer->address(), _1, r.length, _2, _3)
|
||||||
, reinterpret_cast<void*>(1));
|
, reinterpret_cast<void*>(1));
|
||||||
m_block_hashes.erase(i++);
|
i = m_block_hashes.erase(i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -141,10 +141,9 @@ namespace
|
||||||
int size = m_torrent.torrent_file().piece_size(p);
|
int size = m_torrent.torrent_file().piece_size(p);
|
||||||
peer_request r = {p, 0, (std::min)(16*1024, size)};
|
peer_request r = {p, 0, (std::min)(16*1024, size)};
|
||||||
piece_block pb(p, 0);
|
piece_block pb(p, 0);
|
||||||
for (std::vector<torrent_peer*>::iterator i = downloaders.begin()
|
for (auto const& i : downloaders)
|
||||||
, end(downloaders.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (*i != nullptr)
|
if (i != nullptr)
|
||||||
{
|
{
|
||||||
// for very sad and involved reasons, this read need to force a copy out of the cache
|
// for very sad and involved reasons, this read need to force a copy out of the cache
|
||||||
// since the piece has failed, this block is very likely to be replaced with a newly
|
// since the piece has failed, this block is very likely to be replaced with a newly
|
||||||
|
@ -152,7 +151,7 @@ namespace
|
||||||
// block read will have been deleted by the time it gets back to the network thread
|
// block read will have been deleted by the time it gets back to the network thread
|
||||||
m_torrent.session().disk_thread().async_read(m_torrent.storage(), r
|
m_torrent.session().disk_thread().async_read(m_torrent.storage(), r
|
||||||
, std::bind(&smart_ban_plugin::on_read_failed_block
|
, std::bind(&smart_ban_plugin::on_read_failed_block
|
||||||
, shared_from_this(), pb, (*i)->address(), _1, r.length, _2, _3)
|
, shared_from_this(), pb, i->address(), _1, r.length, _2, _3)
|
||||||
, reinterpret_cast<torrent_peer*>(1)
|
, reinterpret_cast<torrent_peer*>(1)
|
||||||
, disk_io_job::force_copy);
|
, disk_io_job::force_copy);
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,29 +179,28 @@ namespace libtorrent
|
||||||
std::string print_listen_interfaces(std::vector<listen_interface_t> const& in)
|
std::string print_listen_interfaces(std::vector<listen_interface_t> const& in)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
for (std::vector<listen_interface_t>::const_iterator i = in.begin()
|
for (auto const& i : in)
|
||||||
, end(in.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (i != in.begin()) ret += ",";
|
if (!ret.empty()) ret += ",";
|
||||||
|
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
error_code ec;
|
error_code ec;
|
||||||
address_v6::from_string(i->device, ec);
|
address_v6::from_string(i.device, ec);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
// IPv6 addresses must be wrapped in square brackets
|
// IPv6 addresses must be wrapped in square brackets
|
||||||
ret += "[";
|
ret += "[";
|
||||||
ret += i->device;
|
ret += i.device;
|
||||||
ret += "]";
|
ret += "]";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ret += i->device;
|
ret += i.device;
|
||||||
}
|
}
|
||||||
ret += ":";
|
ret += ":";
|
||||||
ret += to_string(i->port).data();
|
ret += to_string(i.port).data();
|
||||||
if (i->ssl) ret += "s";
|
if (i.ssl) ret += "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -727,10 +727,9 @@ namespace libtorrent
|
||||||
|
|
||||||
// insert all directories first, to make sure no files
|
// insert all directories first, to make sure no files
|
||||||
// are allowed to collied with them
|
// are allowed to collied with them
|
||||||
for (std::vector<std::string>::const_iterator i = paths.begin()
|
for (auto const& i : paths)
|
||||||
, end(paths.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
std::string p = combine_path(m_files.name(), *i);
|
std::string p = combine_path(m_files.name(), i);
|
||||||
files.insert(p);
|
files.insert(p);
|
||||||
while (has_parent_path(p))
|
while (has_parent_path(p))
|
||||||
{
|
{
|
||||||
|
|
|
@ -200,14 +200,13 @@ namespace libtorrent { namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::set<tcp::endpoint>::const_iterator i = dropped.begin()
|
for (auto const& i : dropped)
|
||||||
, end(dropped.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
if (i->address().is_v4())
|
if (i.address().is_v4())
|
||||||
detail::write_endpoint(*i, pld_out);
|
detail::write_endpoint(i, pld_out);
|
||||||
#if TORRENT_USE_IPV6
|
#if TORRENT_USE_IPV6
|
||||||
else
|
else
|
||||||
detail::write_endpoint(*i, pld6_out);
|
detail::write_endpoint(i, pld6_out);
|
||||||
#endif
|
#endif
|
||||||
++m_peers_in_message;
|
++m_peers_in_message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,23 +67,22 @@ namespace libtorrent
|
||||||
|
|
||||||
utp_socket_manager::~utp_socket_manager()
|
utp_socket_manager::~utp_socket_manager()
|
||||||
{
|
{
|
||||||
for (socket_map_t::iterator i = m_utp_sockets.begin()
|
for (auto& i : m_utp_sockets)
|
||||||
, end(m_utp_sockets.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
delete_utp_impl(i->second);
|
delete_utp_impl(i.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void utp_socket_manager::tick(time_point now)
|
void utp_socket_manager::tick(time_point now)
|
||||||
{
|
{
|
||||||
for (socket_map_t::iterator i = m_utp_sockets.begin()
|
for (auto i = m_utp_sockets.begin()
|
||||||
, end(m_utp_sockets.end()); i != end;)
|
, end(m_utp_sockets.end()); i != end;)
|
||||||
{
|
{
|
||||||
if (should_delete(i->second))
|
if (should_delete(i->second))
|
||||||
{
|
{
|
||||||
delete_utp_impl(i->second);
|
delete_utp_impl(i->second);
|
||||||
if (m_last_socket == i->second) m_last_socket = nullptr;
|
if (m_last_socket == i->second) m_last_socket = nullptr;
|
||||||
m_utp_sockets.erase(i++);
|
i = m_utp_sockets.erase(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tick_utp_impl(i->second, now);
|
tick_utp_impl(i->second, now);
|
||||||
|
|
|
@ -936,11 +936,10 @@ void utp_stream::add_write_buffer(void const* buf, size_t len)
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
int write_buffer_size = 0;
|
int write_buffer_size = 0;
|
||||||
for (std::vector<utp_socket_impl::iovec_t>::iterator i = m_impl->m_write_buffer.begin()
|
for (auto const& i : m_impl->m_write_buffer)
|
||||||
, end(m_impl->m_write_buffer.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i->len) > write_buffer_size);
|
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i.len) > write_buffer_size);
|
||||||
write_buffer_size += int(i->len);
|
write_buffer_size += int(i.len);
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size);
|
TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -950,11 +949,10 @@ void utp_stream::add_write_buffer(void const* buf, size_t len)
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
write_buffer_size = 0;
|
write_buffer_size = 0;
|
||||||
for (std::vector<utp_socket_impl::iovec_t>::iterator i = m_impl->m_write_buffer.begin()
|
for (auto const& i : m_impl->m_write_buffer)
|
||||||
, end(m_impl->m_write_buffer.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i->len) > write_buffer_size);
|
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i.len) > write_buffer_size);
|
||||||
write_buffer_size += int(i->len);
|
write_buffer_size += int(i.len);
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size);
|
TORRENT_ASSERT(m_impl->m_write_buffer_size == write_buffer_size);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1000,7 +998,7 @@ size_t utp_stream::read_some(bool clear_buffers)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<utp_socket_impl::iovec_t>::iterator target = m_impl->m_read_buffer.begin();
|
auto target = m_impl->m_read_buffer.begin();
|
||||||
|
|
||||||
std::size_t ret = 0;
|
std::size_t ret = 0;
|
||||||
|
|
||||||
|
@ -1544,17 +1542,16 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size)
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
int write_buffer_size = 0;
|
int write_buffer_size = 0;
|
||||||
for (std::vector<iovec_t>::iterator i = m_write_buffer.begin()
|
for (auto const& i : m_write_buffer)
|
||||||
, end(m_write_buffer.end()); i != end; ++i)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i->len) > write_buffer_size);
|
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(i.len) > write_buffer_size);
|
||||||
write_buffer_size += int(i->len);
|
write_buffer_size += int(i.len);
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(m_write_buffer_size == write_buffer_size);
|
TORRENT_ASSERT(m_write_buffer_size == write_buffer_size);
|
||||||
#endif
|
#endif
|
||||||
TORRENT_ASSERT(!m_write_buffer.empty() || size == 0);
|
TORRENT_ASSERT(!m_write_buffer.empty() || size == 0);
|
||||||
TORRENT_ASSERT(m_write_buffer_size >= size);
|
TORRENT_ASSERT(m_write_buffer_size >= size);
|
||||||
std::vector<iovec_t>::iterator i = m_write_buffer.begin();
|
auto i = m_write_buffer.begin();
|
||||||
|
|
||||||
if (size == 0) return;
|
if (size == 0) return;
|
||||||
|
|
||||||
|
@ -1583,11 +1580,10 @@ void utp_socket_impl::write_payload(std::uint8_t* ptr, int size)
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
write_buffer_size = 0;
|
write_buffer_size = 0;
|
||||||
for (std::vector<iovec_t>::iterator j = m_write_buffer.begin()
|
for (auto const& j : m_write_buffer)
|
||||||
, end(m_write_buffer.end()); j != end; ++j)
|
|
||||||
{
|
{
|
||||||
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(j->len) > write_buffer_size);
|
TORRENT_ASSERT(std::numeric_limits<int>::max() - int(j.len) > write_buffer_size);
|
||||||
write_buffer_size += int(j->len);
|
write_buffer_size += int(j.len);
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(m_write_buffer_size == write_buffer_size);
|
TORRENT_ASSERT(m_write_buffer_size == write_buffer_size);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -142,12 +142,11 @@ namespace libtorrent
|
||||||
request += base64encode(sett.get_str(settings_pack::proxy_username)
|
request += base64encode(sett.get_str(settings_pack::proxy_username)
|
||||||
+ ":" + sett.get_str(settings_pack::proxy_password));
|
+ ":" + sett.get_str(settings_pack::proxy_password));
|
||||||
}
|
}
|
||||||
for (web_seed_entry::headers_t::const_iterator it = m_extra_headers.begin();
|
for (auto const& h : m_extra_headers) {
|
||||||
it != m_extra_headers.end(); ++it) {
|
|
||||||
request += "\r\n";
|
request += "\r\n";
|
||||||
request += it->first;
|
request += h.first;
|
||||||
request += ": ";
|
request += ": ";
|
||||||
request += it->second;
|
request += h.second;
|
||||||
}
|
}
|
||||||
if (using_proxy) {
|
if (using_proxy) {
|
||||||
request += "\r\nProxy-Connection: keep-alive";
|
request += "\r\nProxy-Connection: keep-alive";
|
||||||
|
|
Loading…
Reference in New Issue