some cast cleanup, const modifier and lint refactor

This commit is contained in:
Alden Torres 2018-05-29 10:45:15 -04:00 committed by Arvid Norberg
parent c2ea38fdfe
commit f9b43f3511
3 changed files with 24 additions and 23 deletions

View File

@ -167,8 +167,8 @@ int udp_socket::read(span<packet> pkts, error_code& ec)
while (ret < num) while (ret < num)
{ {
int const len = int(m_socket.receive_from(boost::asio::buffer(*m_buf) std::size_t const len = m_socket.receive_from(boost::asio::buffer(*m_buf)
, p.from, 0, ec)); , p.from, 0, ec);
if (ec == error::would_block if (ec == error::would_block
|| ec == error::try_again || ec == error::try_again
@ -197,7 +197,7 @@ int udp_socket::read(span<packet> pkts, error_code& ec)
} }
else else
{ {
p.data = {m_buf->data(), aux::numeric_cast<std::size_t>(len)}; p.data = {m_buf->data(), len};
// support packets coming from the SOCKS5 proxy // support packets coming from the SOCKS5 proxy
if (m_socks5_connection && m_socks5_connection->active()) if (m_socks5_connection && m_socks5_connection->active())

View File

@ -520,7 +520,7 @@ namespace libtorrent {
aux::write_uint32(0x27101980, view); // connection_id aux::write_uint32(0x27101980, view); // connection_id
aux::write_int32(action_t::connect, view); // action (connect) aux::write_int32(action_t::connect, view); // action (connect)
aux::write_int32(m_transaction_id, view); // transaction_id aux::write_int32(m_transaction_id, view); // transaction_id
TORRENT_ASSERT(view.size() == 0); TORRENT_ASSERT(view.empty());
error_code ec; error_code ec;
if (!m_hostname.empty()) if (!m_hostname.empty())
@ -627,7 +627,7 @@ namespace libtorrent {
#endif #endif
6; 6;
int const num_peers = static_cast<int>(buf.size() / ip_stride); std::size_t const num_peers = buf.size() / ip_stride;
if (buf.size() % ip_stride != 0) if (buf.size() % ip_stride != 0)
{ {
fail(error_code(errors::invalid_tracker_response_length)); fail(error_code(errors::invalid_tracker_response_length));
@ -651,8 +651,8 @@ namespace libtorrent {
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
if (is_v6(m_target)) if (is_v6(m_target))
{ {
resp.peers6.reserve(std::size_t(num_peers)); resp.peers6.reserve(num_peers);
for (int i = 0; i < num_peers; ++i) for (std::size_t i = 0; i < num_peers; ++i)
{ {
ipv6_peer_entry e{}; ipv6_peer_entry e{};
std::memcpy(e.ip.data(), buf.data(), 16); std::memcpy(e.ip.data(), buf.data(), 16);
@ -664,8 +664,8 @@ namespace libtorrent {
else else
#endif #endif
{ {
resp.peers4.reserve(std::size_t(num_peers)); resp.peers4.reserve(num_peers);
for (int i = 0; i < num_peers; ++i) for (std::size_t i = 0; i < num_peers; ++i)
{ {
ipv4_peer_entry e{}; ipv4_peer_entry e{};
std::memcpy(e.ip.data(), buf.data(), 4); std::memcpy(e.ip.data(), buf.data(), 4);

View File

@ -149,6 +149,9 @@ namespace libtorrent {namespace {
m_requested_metadata.resize(div_round_up(size, 16 * 1024)); m_requested_metadata.resize(div_round_up(size, 16 * 1024));
} }
// explicitly disallow assignment, to silence msvc warning
ut_metadata_plugin& operator=(ut_metadata_plugin const&) = delete;
private: private:
torrent& m_torrent; torrent& m_torrent;
@ -174,9 +177,6 @@ namespace libtorrent {namespace {
// block has been requested and who we ended up getting it from // block has been requested and who we ended up getting it from
// std::numeric_limits<int>::max() means we have the piece // std::numeric_limits<int>::max() means we have the piece
aux::vector<metadata_piece> m_requested_metadata; aux::vector<metadata_piece> m_requested_metadata;
// explicitly disallow assignment, to silence msvc warning
ut_metadata_plugin& operator=(ut_metadata_plugin const&);
}; };
@ -253,17 +253,17 @@ namespace libtorrent {namespace {
if (type == 1) if (type == 1)
{ {
TORRENT_ASSERT(piece >= 0 && piece < int(m_tp.get_metadata_size() + 16 * 1024 - 1)/(16*1024)); TORRENT_ASSERT(piece >= 0 && piece < (m_tp.get_metadata_size() + 16 * 1024 - 1) / (16 * 1024));
TORRENT_ASSERT(m_pc.associated_torrent().lock()->valid_metadata()); TORRENT_ASSERT(m_pc.associated_torrent().lock()->valid_metadata());
TORRENT_ASSERT(m_torrent.valid_metadata()); TORRENT_ASSERT(m_torrent.valid_metadata());
int offset = piece * 16 * 1024; int const offset = piece * 16 * 1024;
metadata = m_tp.metadata().data() + offset; metadata = m_tp.metadata().data() + offset;
metadata_piece_size = std::min( metadata_piece_size = std::min(
m_tp.get_metadata_size() - offset, 16 * 1024); m_tp.get_metadata_size() - offset, 16 * 1024);
TORRENT_ASSERT(metadata_piece_size > 0); TORRENT_ASSERT(metadata_piece_size > 0);
TORRENT_ASSERT(offset >= 0); TORRENT_ASSERT(offset >= 0);
TORRENT_ASSERT(offset + metadata_piece_size <= int(m_tp.get_metadata_size())); TORRENT_ASSERT(offset + metadata_piece_size <= m_tp.get_metadata_size());
} }
// TODO: 3 use the aux::write_* functions and the span here instead, it // TODO: 3 use the aux::write_* functions and the span here instead, it
@ -291,8 +291,8 @@ namespace libtorrent {namespace {
m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_metadata); m_pc.stats_counters().inc_stats_counter(counters::num_outgoing_metadata);
} }
bool on_extended(int length bool on_extended(int const length
, int extended_msg, span<char const> body) override , int const extended_msg, span<char const> body) override
{ {
if (extended_msg != 2) return false; if (extended_msg != 2) return false;
if (m_message_index == 0) return false; if (m_message_index == 0) return false;
@ -455,6 +455,9 @@ namespace libtorrent {namespace {
m_request_limit = now + seconds(20 + random(50)); m_request_limit = now + seconds(20 + random(50));
} }
// explicitly disallow assignment, to silence msvc warning
ut_metadata_peer_plugin& operator=(ut_metadata_peer_plugin const&) = delete;
private: private:
// this is the message index the remote peer uses // this is the message index the remote peer uses
@ -474,9 +477,6 @@ namespace libtorrent {namespace {
torrent& m_torrent; torrent& m_torrent;
bt_peer_connection& m_pc; bt_peer_connection& m_pc;
ut_metadata_plugin& m_tp; ut_metadata_plugin& m_tp;
// explicitly disallow assignment, to silence msvc warning
ut_metadata_peer_plugin& operator=(ut_metadata_peer_plugin const&);
}; };
std::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection( std::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection(
@ -507,7 +507,7 @@ namespace libtorrent {namespace {
int const piece = int(i - m_requested_metadata.begin()); int const piece = int(i - m_requested_metadata.begin());
// don't request the same block more than once every 3 seconds // don't request the same block more than once every 3 seconds
time_point now = aux::time_now(); time_point const now = aux::time_now();
if (m_requested_metadata[piece].last_request != min_time() if (m_requested_metadata[piece].last_request != min_time()
&& total_seconds(now - m_requested_metadata[piece].last_request) < 3) && total_seconds(now - m_requested_metadata[piece].last_request) < 3)
return -1; return -1;
@ -595,7 +595,7 @@ namespace libtorrent {namespace {
{ {
if (!m_torrent.valid_metadata()) if (!m_torrent.valid_metadata())
{ {
time_point now = aux::time_now(); time_point const now = aux::time_now();
// any peer that we downloaded metadata from gets a random time // any peer that we downloaded metadata from gets a random time
// penalty, from 5 to 30 seconds or so. During this time we don't // penalty, from 5 to 30 seconds or so. During this time we don't
// make any metadata requests from those peers (to mix it up a bit // make any metadata requests from those peers (to mix it up a bit
@ -622,7 +622,8 @@ namespace libtorrent {namespace {
metadata(); metadata();
// clear the storage for the bitfield // clear the storage for the bitfield
std::vector<metadata_piece>().swap(m_requested_metadata); m_requested_metadata.clear();
m_requested_metadata.shrink_to_fit();
return true; return true;
} }