minor code refactor and cleanup

This commit is contained in:
Alden Torres 2017-01-13 18:27:09 -05:00 committed by Arvid Norberg
parent 1874a917b0
commit c3d9614dfb
6 changed files with 23 additions and 28 deletions

View File

@ -177,4 +177,3 @@ namespace libtorrent
}
#endif

View File

@ -95,7 +95,7 @@ namespace libtorrent
TORRENT_EXTRA_EXPORT tracker_response parse_tracker_response(
char const* data, int size, error_code& ec
, int flags, sha1_hash scrape_ih);
, int flags, sha1_hash const& scrape_ih);
TORRENT_EXTRA_EXPORT bool extract_peer_info(bdecode_node const& info
, peer_entry& ret, error_code& ec);

View File

@ -363,7 +363,7 @@ namespace libtorrent
b1[i] &= m[i];
b2[i] &= m[i];
}
return memcmp(&b1[0], &b2[0], b1.size()) == 0;
return std::memcmp(b1.data(), b2.data(), b1.size()) == 0;
}
#endif
return (a1.to_v4().to_ulong() & mask.to_v4().to_ulong())
@ -379,10 +379,9 @@ namespace libtorrent
bool in_local_network(std::vector<ip_interface> const& net, address const& addr)
{
for (std::vector<ip_interface>::const_iterator i = net.begin()
, end(net.end()); i != end; ++i)
for (auto const& i : net)
{
if (match_addr_mask(addr, i->interface_address, i->netmask))
if (match_addr_mask(addr, i.interface_address, i.netmask))
return true;
}
return false;
@ -703,7 +702,7 @@ namespace libtorrent
address get_default_gateway(io_service& ios, error_code& ec)
{
std::vector<ip_route> ret = enum_routes(ios, ec);
std::vector<ip_route>::iterator i = std::find_if(ret.begin(), ret.end()
auto const i = std::find_if(ret.begin(), ret.end()
, [](ip_route const& r) { return r.destination == address(); });
if (i == ret.end()) return address();
return i->gateway;
@ -845,9 +844,9 @@ namespace libtorrent
}
close(s);
*/
int mib[6] = { CTL_NET, PF_ROUTE, 0, AF_UNSPEC, NET_RT_DUMP, 0};
int mib[6] = {CTL_NET, PF_ROUTE, 0, AF_UNSPEC, NET_RT_DUMP, 0};
size_t needed = 0;
std::size_t needed = 0;
#ifdef TORRENT_OS2
if (__libsocket_sysctl(mib, 6, 0, &needed, 0, 0) < 0)
#else

View File

@ -1138,4 +1138,3 @@ namespace libtorrent
} // namespace aux
}

View File

@ -260,7 +260,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(nullptr), 0));
, me, ec, nullptr, 0));
return;
}
@ -339,7 +339,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(nullptr), 0));
, me, ec, nullptr, 0));
return;
}
}
@ -355,12 +355,12 @@ void http_connection::start(std::string const& hostname, int port
if (m_bind_addr != address_v4::any())
{
m_sock.open(m_bind_addr.is_v4()?tcp::v4():tcp::v6(), ec);
m_sock.open(m_bind_addr.is_v4() ? tcp::v4() : tcp::v6(), ec);
m_sock.bind(tcp::endpoint(m_bind_addr, 0), ec);
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(nullptr), 0));
, me, ec, nullptr, 0));
return;
}
}
@ -369,7 +369,7 @@ void http_connection::start(std::string const& hostname, int port
if (ec)
{
m_timer.get_io_service().post(std::bind(&http_connection::callback
, me, ec, static_cast<char*>(nullptr), 0));
, me, ec, nullptr, 0));
return;
}
@ -518,9 +518,8 @@ void http_connection::on_resolve(error_code const& e
}
TORRENT_ASSERT(!addresses.empty());
for (std::vector<address>::const_iterator i = addresses.begin()
, end(addresses.end()); i != end; ++i)
m_endpoints.push_back(tcp::endpoint(*i, m_port));
for (auto const& addr : addresses)
m_endpoints.push_back({addr, m_port});
if (m_filter_handler) m_filter_handler(*this, m_endpoints);
if (m_endpoints.empty())
@ -793,7 +792,7 @@ void http_connection::on_read(error_code const& e
if (!m_bottled && m_parser.header_finished())
{
if (m_read_pos > m_parser.body_start())
callback(e, &m_recvbuffer[0] + m_parser.body_start()
callback(e, m_recvbuffer.data() + m_parser.body_start()
, m_read_pos - m_parser.body_start());
m_read_pos = 0;
m_last_receive = clock_type::now();
@ -810,14 +809,14 @@ void http_connection::on_read(error_code const& e
else
{
TORRENT_ASSERT(!m_bottled);
callback(e, &m_recvbuffer[0], m_read_pos);
callback(e, m_recvbuffer.data(), m_read_pos);
m_read_pos = 0;
m_last_receive = clock_type::now();
}
// if we've hit the limit, double the buffer size
if (int(m_recvbuffer.size()) == m_read_pos)
m_recvbuffer.resize((std::min)(m_read_pos * 2, m_max_bottled_buffer_size));
m_recvbuffer.resize(std::min(m_read_pos * 2, m_max_bottled_buffer_size));
if (m_read_pos == m_max_bottled_buffer_size)
{
@ -841,7 +840,7 @@ void http_connection::on_read(error_code const& e
}
}
ADD_OUTSTANDING_ASYNC("http_connection::on_read");
m_sock.async_read_some(boost::asio::buffer(&m_recvbuffer[0] + m_read_pos
m_sock.async_read_some(boost::asio::buffer(m_recvbuffer.data() + m_read_pos
, amount_to_read)
, std::bind(&http_connection::on_read
, me, _1, _2));
@ -871,7 +870,7 @@ void http_connection::on_assign_bandwidth(error_code const& e)
if (!m_sock.is_open()) return;
ADD_OUTSTANDING_ASYNC("http_connection::on_read");
m_sock.async_read_some(boost::asio::buffer(&m_recvbuffer[0] + m_read_pos
m_sock.async_read_some(boost::asio::buffer(m_recvbuffer.data() + m_read_pos
, amount_to_read)
, std::bind(&http_connection::on_read
, shared_from_this(), _1, _2));

View File

@ -101,7 +101,7 @@ namespace libtorrent
// if request-string already contains
// some parameters, append an ampersand instead
// of a question mark
size_t arguments_start = url.find('?');
std::size_t arguments_start = url.find('?');
if (arguments_start != std::string::npos)
url += "&";
else
@ -264,8 +264,7 @@ namespace libtorrent
if (!tracker_req().filter) return;
// remove endpoints that are filtered by the IP filter
for (std::vector<tcp::endpoint>::iterator i = endpoints.begin();
i != endpoints.end();)
for (auto i = endpoints.begin(); i != endpoints.end();)
{
if (tracker_req().filter->access(i->address()) == ip_filter::blocked)
i = endpoints.erase(i);
@ -412,8 +411,8 @@ namespace libtorrent
return true;
}
tracker_response parse_tracker_response(char const* data, int size, error_code& ec
, int flags, sha1_hash scrape_ih)
tracker_response parse_tracker_response(char const* data, int const size, error_code& ec
, int const flags, sha1_hash const& scrape_ih)
{
tracker_response resp;