fixing sign-conversion warnings, part 5, minor refactor (#1559)

fixing sign-conversion warnings, part 5, minor refactor
This commit is contained in:
Alden Torres 2017-01-16 21:51:49 -05:00 committed by Arvid Norberg
parent 5736237a63
commit a5825c0d2e
19 changed files with 52 additions and 48 deletions

View File

@ -144,7 +144,7 @@ private:
void callback(error_code e, char* data = nullptr, int size = 0);
std::vector<char> m_recvbuffer;
aux::vector<char> m_recvbuffer;
std::string m_hostname;
std::string m_url;

View File

@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/proxy_base.hpp"
#include "libtorrent/session_settings.hpp"
#include "libtorrent/string_util.hpp"
#include "libtorrent/aux_/vector.hpp"
namespace libtorrent {
@ -139,7 +140,7 @@ private:
void send_session_create(handler_type h);
// send and receive buffer
std::vector<char> m_buffer;
aux::vector<char> m_buffer;
char const* m_id;
int m_command; // 0 = connect, 1 = accept
std::string m_dest;

View File

@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <libtorrent/session_settings.hpp>
#include <libtorrent/assert.hpp>
#include <libtorrent/time.hpp>
#include <libtorrent/aux_/vector.hpp>
namespace libtorrent
{
@ -58,7 +59,7 @@ namespace libtorrent { namespace dht
{
struct dht_logger;
typedef std::vector<node_entry> bucket_t;
typedef aux::vector<node_entry> bucket_t;
struct routing_table_node
{
@ -147,7 +148,7 @@ public:
// TODO: 3 to improve memory locality and scanning performance, turn the
// routing table into a single vector with boundaries for the nodes instead.
// Perhaps replacement nodes should be in a separate vector.
using table_t = std::vector<routing_table_node>;
using table_t = aux::vector<routing_table_node>;
routing_table(node_id const& id, udp proto
, int bucket_size

View File

@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/span.hpp"
#include "libtorrent/piece_block.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/aux_/vector.hpp"
#include <ctime>
#include <algorithm>
@ -767,12 +768,12 @@ namespace libtorrent
// the queue of blocks we have requested
// from this peer
std::vector<pending_block> m_download_queue;
aux::vector<pending_block> m_download_queue;
// the queue of requests we have got
// from this peer that haven't been issued
// to the disk thread yet
std::vector<peer_request> m_requests;
aux::vector<peer_request> m_requests;
// this peer's peer info struct. This may
// be 0, in case the connection is incoming

View File

@ -727,7 +727,7 @@ namespace libtorrent
// these are indices to the priority boundaries inside
// the m_pieces vector. priority 0 always start at
// 0, priority 1 starts at m_priority_boundaries[0] etc.
mutable std::vector<prio_index_t> m_priority_boundaries;
mutable aux::vector<prio_index_t> m_priority_boundaries;
// each piece that's currently being downloaded has an entry in this list
// with block allocations. i.e. it says which parts of the piece that is
@ -737,12 +737,12 @@ namespace libtorrent
// corresponding downloading_piece vector is piece_open and
// piece_downloading_reverse (the latter uses the same as
// piece_downloading).
std::vector<downloading_piece> m_downloads[piece_pos::num_download_categories];
aux::vector<downloading_piece> m_downloads[piece_pos::num_download_categories];
// this holds the information of the blocks in partially downloaded
// pieces. the downloading_piece::info index point into this vector for
// its storage
std::vector<block_info> m_block_info;
aux::vector<block_info> m_block_info;
// these are block ranges in m_block_info that are free. The numbers
// in here, when multiplied by m_blocks_per_piece is the index to the

View File

@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/web_connection_base.hpp"
#include "libtorrent/piece_block_progress.hpp"
#include "libtorrent/operations.hpp" // for operation_t enum
#include "libtorrent/aux_/vector.hpp"
namespace libtorrent
{
@ -116,7 +117,7 @@ namespace libtorrent
// TODO: 3 if we make this be a disk_buffer_holder instead
// we would save a copy
// use allocate_disk_receive_buffer and release_disk_receive_buffer
std::vector<char> m_piece;
aux::vector<char> m_piece;
// the number of bytes we've forwarded to the incoming_payload() function
// in the current HTTP response. used to know where in the buffer the

View File

@ -841,7 +841,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.data() + m_read_pos
, amount_to_read)
, std::size_t(amount_to_read))
, std::bind(&http_connection::on_read
, me, _1, _2));
}
@ -871,7 +871,7 @@ void http_connection::on_assign_bandwidth(error_code const& e)
ADD_OUTSTANDING_ASYNC("http_connection::on_read");
m_sock.async_read_some(boost::asio::buffer(m_recvbuffer.data() + m_read_pos
, amount_to_read)
, std::size_t(amount_to_read))
, std::bind(&http_connection::on_read
, shared_from_this(), _1, _2));

View File

@ -138,7 +138,7 @@ namespace libtorrent
{
TORRENT_ASSERT(recv_buffer.size() >= m_recv_buffer.size());
std::tuple<int, int> ret(0, 0);
size_t start_pos = m_recv_buffer.size();
std::size_t start_pos = m_recv_buffer.size();
// early exit if there's nothing new in the receive buffer
if (start_pos == recv_buffer.size()) return ret;
@ -206,7 +206,7 @@ restart_response:
m_status_code = 0;
}
m_state = read_header;
start_pos = pos - recv_buffer.data();
start_pos = std::size_t(pos - recv_buffer.data());
}
if (m_state == read_header)
@ -525,7 +525,7 @@ restart_response:
? (std::min)(m_chunked_ranges.back().second - m_body_start_pos, received)
: m_content_length < 0 ? received : (std::min)(m_content_length, received);
return m_recv_buffer.subspan(m_body_start_pos, std::size_t(body_length));
return m_recv_buffer.subspan(std::size_t(m_body_start_pos), std::size_t(body_length));
}
void http_parser::reset()
@ -566,7 +566,7 @@ restart_response:
TORRENT_ASSERT(i.second - offset <= size);
int len = int(i.second - i.first);
if (i.first - offset + len > size) len = size - int(i.first) + offset;
std::memmove(write_ptr, buffer + i.first - offset, len);
std::memmove(write_ptr, buffer + i.first - offset, std::size_t(len));
write_ptr += len;
}
size = int(write_ptr - buffer);

View File

@ -487,7 +487,7 @@ namespace libtorrent
if (peers_ent && peers_ent.type() == bdecode_node::string_t)
{
char const* peers = peers_ent.string_ptr();
int len = peers_ent.string_length();
int const len = peers_ent.string_length();
#if TORRENT_USE_I2P
if (0 != (flags & tracker_request::i2p))
{
@ -504,7 +504,7 @@ namespace libtorrent
else
#endif
{
resp.peers4.reserve(len / 6);
resp.peers4.reserve(std::size_t(len / 6));
for (int i = 0; i < len; i += 6)
{
if (len - i < 6) break;
@ -546,8 +546,8 @@ namespace libtorrent
if (ipv6_peers)
{
char const* peers = ipv6_peers.string_ptr();
int len = ipv6_peers.string_length();
resp.peers6.reserve(len / 18);
int const len = ipv6_peers.string_length();
resp.peers6.reserve(std::size_t(len / 18));
for (int i = 0; i < len; i += 18)
{
if (len - i < 18) break;

View File

@ -455,7 +455,7 @@ namespace libtorrent
int size = std::snprintf(cmd, sizeof(cmd), "STREAM CONNECT ID=%s DESTINATION=%s\n"
, m_id, m_dest.c_str());
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size))
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
@ -466,7 +466,7 @@ namespace libtorrent
char cmd[400];
int size = std::snprintf(cmd, sizeof(cmd), "STREAM ACCEPT ID=%s\n", m_id);
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size))
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
@ -478,7 +478,7 @@ namespace libtorrent
int size = std::snprintf(cmd, sizeof(cmd), "SESSION CREATE STYLE=STREAM ID=%s DESTINATION=TRANSIENT\n"
, m_id);
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size))
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
@ -489,7 +489,7 @@ namespace libtorrent
char cmd[1024];
int size = std::snprintf(cmd, sizeof(cmd), "NAMING LOOKUP NAME=%s\n", m_name_lookup.c_str());
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size))
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
}

View File

@ -261,7 +261,7 @@ namespace
str.resize(18);
std::string::iterator out = str.begin();
detail::write_endpoint(iter->addr, out);
str.resize(out - str.begin());
str.resize(std::size_t(out - str.begin()));
--to_pick;
}

View File

@ -589,12 +589,12 @@ namespace libtorrent { namespace dht
bool dht_tracker::has_quota()
{
time_point now = clock_type::now();
time_duration delta = now - m_last_tick;
time_point const now = clock_type::now();
time_duration const delta = now - m_last_tick;
m_last_tick = now;
// add any new quota we've accrued since last time
m_send_quota += int(std::uint64_t(m_settings.upload_rate_limit)
m_send_quota += int(std::int64_t(m_settings.upload_rate_limit)
* total_microseconds(delta) / 1000000);
// allow 3 seconds worth of burst
@ -629,7 +629,7 @@ namespace libtorrent { namespace dht
return false;
}
m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size());
m_counters.inc_stats_counter(counters::dht_bytes_out, int(m_send_buf.size()));
// account for IP and UDP overhead
m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes
, addr.address().is_v6() ? 48 : 28);

View File

@ -105,8 +105,8 @@ namespace libtorrent
char* ptr = reinterpret_cast<char*>(header.get());
// we have a header. Parse it
int num_pieces_ = read_uint32(ptr);
int piece_size_ = read_uint32(ptr);
int const num_pieces_ = int(read_uint32(ptr));
int const piece_size_ = int(read_uint32(ptr));
// if there is a mismatch in number of pieces or piece size
// consider the file empty and overwrite anything in there
@ -407,7 +407,7 @@ namespace libtorrent
? slot_index_t(-1) : i->second);
write_int32(static_cast<int>(slot), ptr);
}
std::memset(ptr, 0, m_header_size - (ptr - reinterpret_cast<char*>(header.get())));
std::memset(ptr, 0, std::size_t(m_header_size - (ptr - reinterpret_cast<char*>(header.get()))));
iovec_t b = {header.get(), std::size_t(m_header_size)};
m_file.writev(0, b, ec);

View File

@ -535,7 +535,7 @@ namespace libtorrent
std::vector<stats_metric> stats;
int const num = sizeof(metrics) / sizeof(metrics[0]);
stats.resize(num);
for (int i = 0; i < num; ++i)
for (std::size_t i = 0; i < num; ++i)
{
stats[i].name = metrics[i].name;
stats[i].value_index = metrics[i].value_index;

View File

@ -427,7 +427,7 @@ namespace libtorrent
}
return;
}
int extra_bytes = 0;
std::size_t extra_bytes = 0;
if (atyp == 4)
{
// IPv6

View File

@ -864,7 +864,7 @@ namespace libtorrent
// indices of all files we ended up copying. These need to be deleted
// later
aux::vector<bool, file_index_t> copied_files(f.num_files(), false);
aux::vector<bool, file_index_t> copied_files(std::size_t(f.num_files()), false);
file_index_t i;
error_code e;
@ -1176,10 +1176,10 @@ namespace libtorrent
, piece_index_t, int, int, storage_error&) override
{
int ret = 0;
for (int i = 0; i < int(bufs.size()); ++i)
for (auto const& b : bufs)
{
memset(bufs[i].iov_base, 0, bufs[i].iov_len);
ret += int(bufs[i].iov_len);
std::memset(b.iov_base, 0, b.iov_len);
ret += int(b.iov_len);
}
return 0;
}
@ -1187,8 +1187,8 @@ namespace libtorrent
, piece_index_t, int, int, storage_error&) override
{
int ret = 0;
for (int i = 0; i < int(bufs.size()); ++i)
ret += int(bufs[i].iov_len);
for (auto const& b : bufs)
ret += int(b.iov_len);
return 0;
}

View File

@ -47,12 +47,12 @@ namespace libtorrent
// lexical_cast's result depends on the locale. We need
// a well defined result
std::array<char, 4 + std::numeric_limits<std::int64_t>::digits10>
to_string(std::int64_t n)
to_string(std::int64_t const n)
{
std::array<char, 4 + std::numeric_limits<std::int64_t>::digits10> ret;
char *p = &ret.back();
*p = '\0';
std::uint64_t un = n;
std::uint64_t un = std::uint64_t(n);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4146 ) /* warning C4146: unary minus operator applied to unsigned type */
@ -66,7 +66,7 @@ namespace libtorrent
un /= 10;
} while (un);
if (n < 0) *--p = '-';
std::memmove(&ret[0], p, &ret.back() - p + 1);
std::memmove(ret.data(), p, std::size_t(&ret.back() - p + 1));
return ret;
}
@ -160,7 +160,7 @@ namespace libtorrent
char* allocate_string_copy(char const* str)
{
if (str == nullptr) return nullptr;
int const len = int(std::strlen(str));
std::size_t const len = std::strlen(str);
char* tmp = static_cast<char*>(std::malloc(len + 1));
if (tmp == nullptr) return nullptr;
std::memcpy(tmp, str, len);

View File

@ -618,7 +618,7 @@ namespace libtorrent
return true;
}
resp.peers4.reserve(num_peers);
resp.peers4.reserve(std::size_t(num_peers));
for (int i = 0; i < num_peers; ++i)
{
ipv4_peer_entry e;

View File

@ -136,11 +136,11 @@ namespace libtorrent
else mtu -= TORRENT_IPV6_HEADER;
}
utp_mtu = (std::min)(mtu, restrict_mtu());
utp_mtu = std::min(mtu, restrict_mtu());
}
void utp_socket_manager::send_packet(udp::endpoint const& ep, char const* p
, int len, error_code& ec, int flags)
, int const len, error_code& ec, int const flags)
{
#if !defined TORRENT_HAS_DONT_FRAGMENT && !defined TORRENT_DEBUG_MTU
TORRENT_UNUSED(flags);
@ -151,7 +151,7 @@ namespace libtorrent
if ((flags & dont_fragment) && len > TORRENT_DEBUG_MTU) return;
#endif
m_send_fun(ep, span<char const>(p, len), ec
m_send_fun(ep, {p, std::size_t(len)}, ec
, ((flags & dont_fragment) ? udp_socket::dont_fragment : 0)
| udp_socket::peer_connection);
}