some random cleanup

This commit is contained in:
arvidn 2017-09-12 23:10:11 +02:00 committed by Arvid Norberg
parent 5860655581
commit 93bb84d94c
62 changed files with 297 additions and 293 deletions

View File

@ -4,7 +4,7 @@ dist: trusty
matrix:
fast_finish: true
include:
- env: variant=test_debug sonar_scan=1 toolset=gcc
- env: variant=test_release sonar_scan=1 toolset=gcc
- env: variant=test_debug lint=1 tests=1 toolset=gcc-sanitizer
- env: variant=test_debug sim=1 crypto=openssl toolset=gcc-sanitizer
- env: variant=test_release coverage=1 tests=1 toolset=gcc-coverage python=1
@ -155,7 +155,7 @@ script:
fi'
- 'if [ "$sonar_scan" == "1" ]; then
build-wrapper-linux-x86-64 --out-dir bw-output bjam -a -j3 crypto=$crypto asserts=off invariant-checks=off $toolset variant=$variant -l300 &&
build-wrapper-linux-x86-64 --out-dir bw-output bjam -a -j3 crypto=$crypto $toolset variant=$variant -l300 &&
sonar-scanner -D sonar.login=$SONAR_TOKEN;
fi'

View File

@ -253,7 +253,7 @@ namespace aux {
typedef std::unordered_map<sha1_hash, std::shared_ptr<torrent>> torrent_map;
explicit session_impl(io_service& ios);
virtual ~session_impl();
~session_impl() override;
void start_session(settings_pack pack);

View File

@ -313,8 +313,7 @@ namespace libtorrent { namespace aux {
virtual bool verify_queue_position(torrent const*, int) = 0;
#endif
protected:
~session_interface() {}
virtual ~session_interface() {}
};
}}

View File

@ -93,7 +93,7 @@ namespace libtorrent {
bt_peer_connection(peer_connection_args const& pack
, peer_id const& pid);
virtual void start() override;
void start() override;
enum
{
@ -119,7 +119,7 @@ namespace libtorrent {
void switch_recv_crypto(std::shared_ptr<crypto_plugin> crypto);
#endif
virtual connection_type type() const override
connection_type type() const override
{ return connection_type::bittorrent; }
enum message_type
@ -174,13 +174,12 @@ namespace libtorrent {
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
// next_barrier, buffers-to-prepend
virtual
std::tuple<int, span<span<char const>>>
hit_send_barrier(span<span<char>> iovec) override;
#endif
virtual void get_specific_peer_info(peer_info& p) const override;
virtual bool in_handshake() const override;
void get_specific_peer_info(peer_info& p) const override;
bool in_handshake() const override;
bool packet_finished() const { return m_recv_buffer.packet_finished(); }
#ifndef TORRENT_DISABLE_EXTENSIONS

View File

@ -82,11 +82,11 @@ public:
// the actual allocation may be larger than we requested. If so, let the
// user take advantage of every single byte
#if defined __GLIBC__
m_size = malloc_usable_size(m_begin);
m_size = ::malloc_usable_size(m_begin);
#elif defined _MSC_VER
m_size = _msize(m_begin);
m_size = ::_msize(m_begin);
#elif defined TORRENT_BSD
m_size = malloc_size(m_begin);
m_size = ::malloc_size(m_begin);
#else
m_size = size;
#endif

View File

@ -392,7 +392,7 @@ namespace aux {
{
explicit job_queue(disk_io_thread& owner) : m_owner(owner) {}
virtual void notify_all() override
void notify_all() override
{
m_job_cond.notify_all();
}

View File

@ -59,22 +59,22 @@ namespace libtorrent {
http_seed_connection(peer_connection_args const& pack
, web_seed_t& web);
virtual connection_type type() const override
connection_type type() const override
{ return connection_type::http_seed; }
// called from the main loop when this connection has any
// work to do.
virtual void on_receive(error_code const& error
void on_receive(error_code const& error
, std::size_t bytes_transferred) override;
virtual void on_connected() override;
void on_connected() override;
std::string const& url() const override { return m_url; }
virtual void get_specific_peer_info(peer_info& p) const override;
virtual void disconnect(error_code const& ec, operation_t op, int error = 0) override;
void get_specific_peer_info(peer_info& p) const override;
void disconnect(error_code const& ec, operation_t op, int error = 0) override;
virtual void write_request(peer_request const& r) override;
void write_request(peer_request const& r) override;
private:

View File

@ -66,8 +66,8 @@ namespace libtorrent {
, tracker_request const& req
, std::weak_ptr<request_callback> c);
void start();
void close();
void start() override;
void close() override;
private:
@ -82,7 +82,7 @@ namespace libtorrent {
void on_response(error_code const& ec, http_parser const& parser
, span<char const> data);
virtual void on_timeout(error_code const&) {}
void on_timeout(error_code const&) override {}
std::shared_ptr<http_connection> m_tracker_connection;
address m_tracker_ip;

View File

@ -180,9 +180,7 @@ namespace detail {
template <class OutIt>
int write_string(std::string const& val, OutIt& out)
{
for (std::string::const_iterator i = val.begin()
, end(val.end()); i != end; ++i)
*out++ = *i;
for (auto const c : val) *out++ = c;
return int(val.length());
}
}

View File

@ -49,7 +49,7 @@ struct direct_traversal : traversal_algorithm
, m_cb(cb)
{}
virtual char const* name() const { return "direct_traversal"; }
char const* name() const override { return "direct_traversal"; }
void invoke_cb(msg const& m)
{
@ -72,13 +72,13 @@ struct direct_observer : observer
: observer(algo, ep, id)
{}
virtual void reply(msg const& m)
void reply(msg const& m) override
{
flags |= flag_done;
static_cast<direct_traversal*>(algorithm())->invoke_cb(m);
}
virtual void timeout()
void timeout() override
{
if (flags & flag_done) return;
flags |= flag_done;

View File

@ -58,15 +58,15 @@ struct find_data : traversal_algorithm
void got_write_token(node_id const& n, std::string write_token);
virtual void start();
void start() override;
virtual char const* name() const;
char const* name() const override;
protected:
virtual void done();
virtual observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id);
void done() override;
observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id) override;
nodes_callback m_nodes_callback;
std::map<node_id, std::string> m_write_tokens;
@ -81,7 +81,7 @@ struct find_data_observer : traversal_observer
: traversal_observer(algorithm, ep, id)
{}
virtual void reply(msg const&);
void reply(msg const&) override;
};
} } // namespace libtorrent::dht

View File

@ -63,13 +63,13 @@ public:
, data_callback const& dcallback
, nodes_callback const& ncallback);
virtual char const* name() const;
char const* name() const override;
protected:
virtual observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id);
virtual bool invoke(observer_ptr o);
virtual void done();
observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id) override;
bool invoke(observer_ptr o) override;
void done() override;
data_callback m_data_callback;
item m_data;
@ -85,7 +85,7 @@ public:
: find_data_observer(algorithm, ep, id)
{}
virtual void reply(msg const&);
void reply(msg const&) override;
};
} } // namespace libtorrent::dht

View File

@ -48,12 +48,12 @@ struct get_peers : find_data
, nodes_callback const& ncallback
, bool noseeds);
virtual char const* name() const;
char const* name() const override;
protected:
virtual bool invoke(observer_ptr o);
virtual observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id);
bool invoke(observer_ptr o) override;
observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id) override;
data_callback m_data_callback;
bool m_noseeds;
@ -68,14 +68,14 @@ struct obfuscated_get_peers : get_peers
, nodes_callback const& ncallback
, bool noseeds);
virtual char const* name() const;
char const* name() const override;
protected:
virtual observer_ptr new_observer(udp::endpoint const& ep,
node_id const& id);
virtual bool invoke(observer_ptr o);
virtual void done();
observer_ptr new_observer(udp::endpoint const& ep,
node_id const& id) override;
bool invoke(observer_ptr o) override;
void done() override;
private:
// when set to false, we no longer obfuscate
// the target hash, and send regular get_peers
@ -90,7 +90,7 @@ struct get_peers_observer : find_data_observer
: find_data_observer(algorithm, ep, id)
{}
virtual void reply(msg const&);
void reply(msg const&) override;
#ifndef TORRENT_DISABLE_LOGGING
private:
void log_peers(msg const& m, bdecode_node const& r, int const size) const;
@ -104,7 +104,7 @@ struct obfuscated_get_peers_observer : traversal_observer
, udp::endpoint const& ep, node_id const& id)
: traversal_observer(algorithm, ep, id)
{}
virtual void reply(msg const&);
void reply(msg const&) override;
};
} } // namespace libtorrent::dht

View File

@ -73,7 +73,7 @@ public:
: observer(algo, ep, id)
{}
void reply(msg const&) { flags |= flag_done; }
void reply(msg const&) override { flags |= flag_done; }
};
struct socket_manager
@ -87,7 +87,7 @@ protected:
// get the closest node to the id with the given family_name
using get_foreign_node_t = std::function<node*(node_id const&, std::string const&)>;
class TORRENT_EXTRA_EXPORT node : boost::noncopyable
class TORRENT_EXTRA_EXPORT node
{
public:
node(aux::listen_socket_handle const& sock, socket_manager* sock_man
@ -99,6 +99,9 @@ public:
~node();
node(node const&) = delete;
node& operator=(node const&) = delete;
void update_node_id();
void tick();

View File

@ -51,8 +51,8 @@ struct put_data: traversal_algorithm
put_data(node& node, put_callback const& callback);
virtual char const* name() const override;
virtual void start() override;
char const* name() const override;
void start() override;
void set_data(item const& data) { m_data = data; }
@ -60,8 +60,8 @@ struct put_data: traversal_algorithm
protected:
virtual void done() override;
virtual bool invoke(observer_ptr o) override;
void done() override;
bool invoke(observer_ptr o) override;
put_callback m_put_callback;
item m_data;
@ -78,7 +78,7 @@ struct put_data_observer : traversal_observer
{
}
virtual void reply(msg const&) { done(); }
void reply(msg const&) override { done(); }
std::string m_token;
};

View File

@ -45,16 +45,16 @@ public:
bootstrap(node& dht_node, node_id const& target
, done_callback const& callback);
virtual char const* name() const;
char const* name() const override;
observer_ptr new_observer(udp::endpoint const& ep
, node_id const& id);
, node_id const& id) override;
protected:
virtual bool invoke(observer_ptr o);
bool invoke(observer_ptr o) override;
virtual void done();
void done() override;
};

View File

@ -55,11 +55,11 @@ struct dht_settings;
struct dht_logger;
struct socket_manager;
struct TORRENT_EXTRA_EXPORT null_observer : public observer
struct TORRENT_EXTRA_EXPORT null_observer : observer
{
null_observer(std::shared_ptr<traversal_algorithm> const& a
, udp::endpoint const& ep, node_id const& id): observer(a, ep, id) {}
virtual void reply(msg const&) { flags |= flag_done; }
void reply(msg const&) override { flags |= flag_done; }
};
class routing_table;

View File

@ -53,7 +53,7 @@ public:
, node_id const& target
, data_callback const& dcallback);
virtual char const* name() const override;
char const* name() const override;
void got_samples(time_duration interval
, int num, std::vector<sha1_hash> samples
@ -71,7 +71,7 @@ public:
sample_infohashes_observer(std::shared_ptr<traversal_algorithm> const& algorithm
, udp::endpoint const& ep, node_id const& id);
virtual void reply(msg const&) override;
void reply(msg const&) override;
};
}} // namespace libtorrent::dht

View File

@ -162,7 +162,7 @@ struct traversal_observer : observer
{}
// parses out "nodes" and keeps traversing
virtual void reply(msg const&);
void reply(msg const&) override;
};
} // namespace dht

View File

@ -79,7 +79,7 @@ private:
void disable(error_code const& ec);
struct mapping_t : public aux::base_mapping
struct mapping_t : aux::base_mapping
{
// the local port for this mapping. If this is set
// to 0, the mapping is not in use

View File

@ -88,9 +88,9 @@ namespace libtorrent {
// sent with the DF bit set (Don't Fragment)
bool mtu_probe:1;
#if TORRENT_USE_ASSERTS
#if TORRENT_USE_ASSERTS
int num_fast_resend;
#endif
#endif
// the actual packet buffer
std::uint8_t buf[1];

View File

@ -63,7 +63,8 @@ namespace libtorrent {
// RC4 state from libtomcrypt
struct rc4 {
int x, y;
int x;
int y;
aux::array<std::uint8_t, 256> buf;
};
@ -88,9 +89,6 @@ namespace libtorrent {
private:
int get_local_key_size() const
{ return sizeof(m_dh_local_key); }
key_t m_dh_local_key;
key_t m_dh_local_secret;
key_t m_dh_shared_secret;

View File

@ -278,7 +278,7 @@ namespace aux {
// do in the constructor).
virtual void start();
virtual ~peer_connection() override;
~peer_connection() override;
void set_peer_info(torrent_peer* pi) override
{
@ -653,7 +653,7 @@ namespace aux {
#endif
time_t last_seen_complete() const { return m_last_seen_complete; }
void set_last_seen_complete(int ago) { m_last_seen_complete = time(0) - ago; }
void set_last_seen_complete(int ago) { m_last_seen_complete = ::time(0) - ago; }
std::int64_t uploaded_in_last_round() const
{ return m_statistics.total_payload_upload() - m_uploaded_at_last_round; }

View File

@ -130,7 +130,7 @@ private:
}
};
struct TORRENT_EXPORT bt_peer_connection_handle : public peer_connection_handle
struct TORRENT_EXPORT bt_peer_connection_handle : peer_connection_handle
{
explicit bt_peer_connection_handle(peer_connection_handle pc)
: peer_connection_handle(pc)

View File

@ -52,12 +52,12 @@ struct TORRENT_EXTRA_EXPORT resolver final : resolver_interface
{
explicit resolver(io_service& ios);
virtual void async_resolve(std::string const& host, resolver_flags flags
void async_resolve(std::string const& host, resolver_flags flags
, callback_t const& h) override;
virtual void abort() override;
void abort() override;
virtual void set_cache_timeout(seconds timeout) override;
void set_cache_timeout(seconds timeout) override;
private:

View File

@ -8,7 +8,8 @@ namespace libtorrent {
struct sha512_ctx
{
std::uint64_t length, state[8];
std::uint64_t length;
std::uint64_t state[8];
std::size_t curlen;
std::uint8_t buf[128];
};

View File

@ -73,9 +73,9 @@ POSSIBILITY OF SUCH DAMAGE.
// struct temp_storage : storage_interface
// {
// temp_storage(file_storage const& fs) : storage_interface(fs) {}
// virtual bool initialize(storage_error& se) { return false; }
// virtual bool has_any_file() { return false; }
// virtual int read(char* buf, int piece, int offset, int size)
// bool initialize(storage_error& se) override { return false; }
// bool has_any_file() override { return false; }
// int read(char* buf, int piece, int offset, int size) override
// {
// std::map<int, std::vector<char>>::const_iterator i = m_file_data.find(piece);
// if (i == m_file_data.end()) return 0;
@ -85,22 +85,22 @@ POSSIBILITY OF SUCH DAMAGE.
// memcpy(buf, &i->second[offset], available);
// return available;
// }
// virtual int write(const char* buf, int piece, int offset, int size)
// int write(const char* buf, int piece, int offset, int size) override
// {
// std::vector<char>& data = m_file_data[piece];
// if (data.size() < offset + size) data.resize(offset + size);
// std::memcpy(&data[offset], buf, size);
// return size;
// }
// virtual bool rename_file(file_index_t file, std::string const& new_name)
// bool rename_file(file_index_t file, std::string const& new_name) override
// { assert(false); return false; }
// virtual status_t move_storage(std::string const& save_path) { return false; }
// virtual bool verify_resume_data(add_torrent_params const& rd
// status_t move_storage(std::string const& save_path) override { return false; }
// bool verify_resume_data(add_torrent_params const& rd
// , std::vector<std::string> const* links
// , storage_error& error) { return false; }
// virtual std::int64_t physical_offset(int piece, int offset)
// , storage_error& error) override { return false; }
// std::int64_t physical_offset(int piece, int offset) override
// { return piece * files().piece_length() + offset; };
// virtual sha1_hash hash_for_slot(int piece, partial_hash& ph, int piece_size)
// sha1_hash hash_for_slot(int piece, partial_hash& ph, int piece_size) override
// {
// int left = piece_size - ph.offset;
// assert(left >= 0);
@ -116,8 +116,8 @@ POSSIBILITY OF SUCH DAMAGE.
// }
// return ph.h.final();
// }
// virtual bool release_files() { return false; }
// virtual bool delete_files() { return false; }
// bool release_files() override { return false; }
// bool delete_files() override { return false; }
//
// std::map<int, std::vector<char>> m_file_data;
// };
@ -161,13 +161,15 @@ namespace libtorrent {
// reads garbage. It's useful mostly for benchmarking and profiling purpose.
//
struct TORRENT_EXPORT storage_interface
: public std::enable_shared_from_this<storage_interface>
, public aux::disk_job_fence
, public aux::storage_piece_set
, boost::noncopyable
: std::enable_shared_from_this<storage_interface>
, aux::disk_job_fence
, aux::storage_piece_set
{
explicit storage_interface(file_storage const& fs) : m_files(fs) {}
storage_interface(storage_interface const&) = delete;
storage_interface& operator=(storage_interface const&) = delete;
// This function is called when the storage is to be initialized. The
// default storage will create directories and empty files at this point.
// If ``allocate_files`` is true, it will also ``ftruncate`` all files to
@ -283,7 +285,7 @@ namespace libtorrent {
//
// .. code:: c++
//
// struct disk_buffer_pool : boost::noncopyable
// struct disk_buffer_pool
// {
// char* allocate_buffer(char const* category);
// void free_buffer(char* buf);
@ -380,20 +382,20 @@ namespace libtorrent {
// hidden
~default_storage() override;
virtual bool has_any_file(storage_error& ec) override;
virtual void set_file_priority(aux::vector<std::uint8_t, file_index_t> const& prio
bool has_any_file(storage_error& ec) override;
void set_file_priority(aux::vector<std::uint8_t, file_index_t> const& prio
, storage_error& ec) override;
virtual void rename_file(file_index_t index, std::string const& new_filename
void rename_file(file_index_t index, std::string const& new_filename
, storage_error& ec) override;
virtual void release_files(storage_error& ec) override;
virtual void delete_files(remove_flags_t options, storage_error& ec) override;
virtual void initialize(storage_error& ec) override;
virtual status_t move_storage(std::string const& save_path
void release_files(storage_error& ec) override;
void delete_files(remove_flags_t options, storage_error& ec) override;
void initialize(storage_error& ec) override;
status_t move_storage(std::string const& save_path
, move_flags_t flags, storage_error& ec) override;
virtual bool verify_resume_data(add_torrent_params const& rd
bool verify_resume_data(add_torrent_params const& rd
, aux::vector<std::string, file_index_t> const& links
, storage_error& error) override;
virtual bool tick() override;
bool tick() override;
int readv(span<iovec_t const> bufs
, piece_index_t piece, int offset, open_mode_t flags, storage_error& ec) override;

View File

@ -700,17 +700,17 @@ namespace libtorrent {
// (either http_tracker_connection or udp_tracker_connection)
// when this torrent got a response from its tracker request
// or when a failure occurred
virtual void tracker_response(
void tracker_response(
tracker_request const& r
, address const& tracker_ip
, std::list<address> const& ip_list
, struct tracker_response const& resp) override;
virtual void tracker_request_error(tracker_request const& r
void tracker_request_error(tracker_request const& r
, int response_code, error_code const& ec, const std::string& msg
, seconds32 retry_interval) override;
virtual void tracker_warning(tracker_request const& req
void tracker_warning(tracker_request const& req
, std::string const& msg) override;
virtual void tracker_scrape_response(tracker_request const& req
void tracker_scrape_response(tracker_request const& req
, int complete, int incomplete, int downloaded, int downloaders) override;
void update_scrape_state();
@ -995,8 +995,8 @@ namespace libtorrent {
void write_resume_data(add_torrent_params& atp) const;
void seen_complete() { m_last_seen_complete = time(0); }
int time_since_complete() const { return int(time(0) - m_last_seen_complete); }
void seen_complete() { m_last_seen_complete = ::time(0); }
int time_since_complete() const { return int(::time(0) - m_last_seen_complete); }
time_t last_seen_complete() const { return m_last_seen_complete; }
template <typename Fun, typename... Args>
@ -1004,8 +1004,8 @@ namespace libtorrent {
// LOGGING
#ifndef TORRENT_DISABLE_LOGGING
virtual bool should_log() const override;
virtual void debug_log(const char* fmt, ...) const override TORRENT_FORMAT(2,3);
bool should_log() const override;
void debug_log(const char* fmt, ...) const override TORRENT_FORMAT(2,3);
void log_to_all_peers(char const* message);
time_point m_dht_start_time;

View File

@ -64,8 +64,8 @@ namespace libtorrent {
{
torrent_peer_allocator();
torrent_peer* allocate_peer_entry(int type);
void free_peer_entry(torrent_peer* p);
torrent_peer* allocate_peer_entry(int type) override;
void free_peer_entry(torrent_peer* p) override;
std::uint64_t total_bytes() const { return m_total_bytes; }
std::uint64_t total_allocations() const { return m_total_allocations; }

View File

@ -253,10 +253,12 @@ namespace libtorrent {
struct TORRENT_EXTRA_EXPORT timeout_handler
: std::enable_shared_from_this<timeout_handler>
, boost::noncopyable
{
explicit timeout_handler(io_service& str);
timeout_handler(timeout_handler const&) = delete;
timeout_handler& operator=(timeout_handler const&) = delete;
void set_timeout(int completion_timeout, int read_timeout);
void restart_read_timeout();
void cancel();
@ -300,7 +302,7 @@ namespace libtorrent {
, std::weak_ptr<request_callback> r);
std::shared_ptr<request_callback> requester() const;
virtual ~tracker_connection() {}
~tracker_connection() override {}
tracker_request const& tracker_req() const { return m_req; }
@ -334,8 +336,7 @@ namespace libtorrent {
};
class TORRENT_EXTRA_EXPORT tracker_manager final
: boost::noncopyable
, single_threaded
: single_threaded
{
public:
@ -357,7 +358,11 @@ namespace libtorrent {
, aux::session_logger& ses
#endif
);
virtual ~tracker_manager();
~tracker_manager();
tracker_manager(tracker_manager const&) = delete;
tracker_manager& operator=(tracker_manager const&) = delete;
void queue_request(
io_service& ios

View File

@ -59,8 +59,8 @@ namespace libtorrent {
, tracker_request const& req
, std::weak_ptr<request_callback> c);
void start();
void close();
void start() override;
void close() override;
std::uint32_t transaction_id() const { return m_transaction_id; }
@ -103,7 +103,7 @@ namespace libtorrent {
void send_udp_announce();
void send_udp_scrape();
virtual void on_timeout(error_code const& ec);
void on_timeout(error_code const& ec) override;
udp::endpoint pick_target_endpoint() const;

View File

@ -246,7 +246,7 @@ private:
tcp::endpoint local_ep;
};
struct mapping_t : public aux::base_mapping
struct mapping_t : aux::base_mapping
{
// the local port for this mapping. If this is set
// to 0, the mapping is not in use

View File

@ -61,44 +61,44 @@ namespace libtorrent {
web_connection_base(peer_connection_args const& pack
, web_seed_t& web);
virtual int timeout() const;
void start();
int timeout() const override;
void start() override;
~web_connection_base();
~web_connection_base() override;
// called from the main loop when this connection has any
// work to do.
void on_sent(error_code const& error
, std::size_t bytes_transferred);
, std::size_t bytes_transferred) override;
virtual std::string const& url() const = 0;
bool in_handshake() const;
bool in_handshake() const override;
// the following functions appends messages
// to the send buffer
void write_choke() {}
void write_unchoke() {}
void write_interested() {}
void write_not_interested() {}
virtual void write_request(peer_request const&) = 0;
void write_cancel(peer_request const&) {}
void write_have(piece_index_t) {}
void write_dont_have(piece_index_t) {}
void write_piece(peer_request const&, disk_buffer_holder)
void write_choke() override {}
void write_unchoke() override {}
void write_interested() override {}
void write_not_interested() override {}
void write_request(peer_request const&) override = 0;
void write_cancel(peer_request const&) override {}
void write_have(piece_index_t) override {}
void write_dont_have(piece_index_t) override {}
void write_piece(peer_request const&, disk_buffer_holder) override
{ TORRENT_ASSERT_FAIL(); }
void write_keepalive() {}
void on_connected();
void write_reject_request(peer_request const&) {}
void write_allow_fast(piece_index_t) {}
void write_suggest(piece_index_t) {}
void write_bitfield() {}
void write_keepalive() override {}
void on_connected() override;
void write_reject_request(peer_request const&) override {}
void write_allow_fast(piece_index_t) override {}
void write_suggest(piece_index_t) override {}
void write_bitfield() override {}
#if TORRENT_USE_INVARIANT_CHECKS
void check_invariant() const;
#endif
virtual void get_specific_peer_info(peer_info& p) const;
void get_specific_peer_info(peer_info& p) const override;
protected:

View File

@ -60,25 +60,25 @@ namespace libtorrent {
web_peer_connection(peer_connection_args const& pack
, web_seed_t& web);
virtual void on_connected() override;
void on_connected() override;
virtual connection_type type() const override
connection_type type() const override
{ return connection_type::url_seed; }
// called from the main loop when this connection has any
// work to do.
virtual void on_receive(error_code const& error
void on_receive(error_code const& error
, std::size_t bytes_transferred) override;
std::string const& url() const override { return m_url; }
virtual void get_specific_peer_info(peer_info& p) const override;
virtual void disconnect(error_code const& ec
void get_specific_peer_info(peer_info& p) const override;
void disconnect(error_code const& ec
, operation_t op, int error = 0) override;
virtual void write_request(peer_request const& r) override;
void write_request(peer_request const& r) override;
virtual bool received_invalid_data(piece_index_t index, bool single_peer) override;
bool received_invalid_data(piece_index_t index, bool single_peer) override;
private:

View File

@ -812,11 +812,11 @@ namespace {
return type_str[sock_type_idx(type)];
}
static char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
char const* const nat_type_str[] = {"NAT-PMP", "UPnP"};
static char const* const protocol_str[] = {"none", "TCP", "UDP"};
char const* const protocol_str[] = {"none", "TCP", "UDP"};
static char const* const socket_type_str[] = {
char const* const socket_type_str[] = {
"null",
"TCP",
"Socks5/TCP",

View File

@ -88,7 +88,7 @@ namespace libtorrent {
#elif defined TORRENT_BEOS
s = B_PAGE_SIZE;
#else
s = int(sysconf(_SC_PAGESIZE));
s = int(::sysconf(_SC_PAGESIZE));
#endif
// assume the page size is 4 kiB if we
// fail to query it
@ -113,12 +113,12 @@ namespace libtorrent {
void* ret;
#if TORRENT_USE_POSIX_MEMALIGN
if (posix_memalign(&ret, std::size_t(page_size()), std::size_t(bytes))
if (::posix_memalign(&ret, std::size_t(page_size()), std::size_t(bytes))
!= 0) ret = nullptr;
#elif TORRENT_USE_MEMALIGN
ret = memalign(std::size_t(page_size()), std::size_t(bytes));
ret = ::memalign(std::size_t(page_size()), std::size_t(bytes));
#elif defined TORRENT_WINDOWS
ret = _aligned_malloc(std::size_t(bytes), std::size_t(page_size()));
ret = ::_aligned_malloc(std::size_t(bytes), std::size_t(page_size()));
#elif defined TORRENT_BEOS
area_id id = create_area("", &ret, B_ANY_ADDRESS
, (bytes + page_size() - 1) & (page_size() - 1), B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);

View File

@ -68,7 +68,7 @@ std::string demangle(char const* name)
{
// in case this string comes
// this is needed on linux
char const* start = strchr(name, '(');
char const* start = std::strchr(name, '(');
if (start != nullptr)
{
++start;
@ -79,14 +79,14 @@ std::string demangle(char const* name)
start = strstr(name, "0x");
if (start != nullptr)
{
start = strchr(start, ' ');
start = std::strchr(start, ' ');
if (start != nullptr) ++start;
else start = name;
}
else start = name;
}
char const* end = strchr(start, '+');
char const* end = std::strchr(start, '+');
if (end) while (*(end-1) == ' ') --end;
std::string in;
@ -98,7 +98,7 @@ std::string demangle(char const* name)
char* unmangled = ::abi::__cxa_demangle(in.c_str(), nullptr, &len, &status);
if (unmangled == nullptr) return in;
std::string ret(unmangled);
free(unmangled);
::free(unmangled);
return ret;
}
#elif defined _WIN32
@ -129,8 +129,8 @@ std::string demangle(char const* name) { return name; }
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
{
void* stack[50];
int size = backtrace(stack, 50);
char** symbols = backtrace_symbols(stack, size);
int size = ::backtrace(stack, 50);
char** symbols = ::backtrace_symbols(stack, size);
for (int i = 1; i < size && len > 0; ++i)
{
@ -140,7 +140,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
if (i - 1 == max_depth && max_depth > 0) break;
}
free(symbols);
::free(symbols);
}
#elif defined _WIN32
@ -292,7 +292,7 @@ TORRENT_EXPORT void assert_print(char const* fmt, ...)
#endif
va_list va;
va_start(va, fmt);
vfprintf(out, fmt, va);
std::vfprintf(out, fmt, va);
va_end(va);
#ifdef TORRENT_PRODUCTION_ASSERTS
@ -358,9 +358,9 @@ TORRENT_EXPORT void assert_fail(char const* expr, int line
#else
// send SIGINT to the current process
// to break into the debugger
raise(SIGINT);
::raise(SIGINT);
#endif
abort();
::abort();
#endif
}

View File

@ -227,6 +227,7 @@ namespace {
bdecode_node& bdecode_node::operator=(bdecode_node const& n)
{
if (&n == this) return *this;
m_tokens = n.m_tokens;
m_root_tokens = n.m_root_tokens;
m_buffer = n.m_buffer;
@ -660,10 +661,9 @@ namespace {
// +1 is to skip the 'i'
char const* ptr = m_buffer + t.offset + 1;
std::int64_t val = 0;
bool negative = false;
if (*ptr == '-') negative = true;
bool const negative = (*ptr == '-');
bdecode_errors::error_code_enum ec = bdecode_errors::no_error;
char const* end = parse_int(ptr + negative
char const* end = parse_int(ptr + int(negative)
, ptr + size, 'e', val, ec);
if (ec) return 0;
TORRENT_UNUSED(end);

View File

@ -141,7 +141,7 @@ namespace libtorrent {
int const new_size_words = num_words();
if (val)
{
if (old_size_words && b) buf()[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b));
if (old_size_words && b) buf()[old_size_words - 1] |= aux::host_to_network(0xffffffff >> b);
if (old_size_words < new_size_words)
std::memset(buf() + old_size_words, 0xff
, std::size_t((new_size_words - old_size_words) * 4));

View File

@ -1328,7 +1328,7 @@ bool block_cache::inc_block_refcount(cached_piece_entry* pe, int block, int reas
case ref_hashing: ++pe->blocks[block].hashing_count; break;
case ref_reading: ++pe->blocks[block].reading_count; break;
case ref_flushing: ++pe->blocks[block].flushing_count; break;
};
}
TORRENT_ASSERT(int(pe->blocks[block].refcount) >= pe->blocks[block].hashing_count
+ pe->blocks[block].reading_count + pe->blocks[block].flushing_count);
#else
@ -1361,7 +1361,7 @@ void block_cache::dec_block_refcount(cached_piece_entry* pe, int block, int reas
case ref_hashing: --pe->blocks[block].hashing_count; break;
case ref_reading: --pe->blocks[block].reading_count; break;
case ref_flushing: --pe->blocks[block].flushing_count; break;
};
}
TORRENT_PIECE_ASSERT(int(pe->blocks[block].refcount) >= pe->blocks[block].hashing_count
+ pe->blocks[block].reading_count + pe->blocks[block].flushing_count, pe);
#else

View File

@ -2400,11 +2400,11 @@ namespace {
if (!m_enc_handler.is_recv_plaintext())
{
int const consumed = m_enc_handler.decrypt(m_recv_buffer, bytes_transferred);
#ifndef TORRENT_DISABLE_LOGGING
#ifndef TORRENT_DISABLE_LOGGING
if (consumed + int(bytes_transferred) > 0)
peer_log(peer_log_alert::incoming_message, "ENCRYPTION"
, "decrypted block s = %d", consumed + int(bytes_transferred));
#endif
#endif
if (bytes_transferred == SIZE_MAX)
{
disconnect(errors::parse_failed, operation_t::encryption);
@ -2424,21 +2424,21 @@ namespace {
while (bytes_transferred > 0 &&
((sub_transferred = m_recv_buffer.advance_pos(int(bytes_transferred))) > 0))
{
#if TORRENT_USE_ASSERTS
std::int64_t cur_payload_dl = m_statistics.last_payload_downloaded();
std::int64_t cur_protocol_dl = m_statistics.last_protocol_downloaded();
#endif
#if TORRENT_USE_ASSERTS
std::int64_t const cur_payload_dl = m_statistics.last_payload_downloaded();
std::int64_t const cur_protocol_dl = m_statistics.last_protocol_downloaded();
#endif
TORRENT_ASSERT(sub_transferred > 0);
on_receive_impl(std::size_t(sub_transferred));
bytes_transferred -= std::size_t(sub_transferred);
#if TORRENT_USE_ASSERTS
#if TORRENT_USE_ASSERTS
TORRENT_ASSERT(m_statistics.last_payload_downloaded() - cur_payload_dl >= 0);
TORRENT_ASSERT(m_statistics.last_protocol_downloaded() - cur_protocol_dl >= 0);
std::int64_t stats_diff = m_statistics.last_payload_downloaded() - cur_payload_dl +
std::int64_t const stats_diff = m_statistics.last_payload_downloaded() - cur_payload_dl +
m_statistics.last_protocol_downloaded() - cur_protocol_dl;
TORRENT_ASSERT(stats_diff == int(sub_transferred));
#endif
#endif
if (m_disconnecting) return;
}
@ -3098,7 +3098,7 @@ namespace {
#ifndef TORRENT_DISABLE_EXTENSIONS
std::memcpy(m_reserved_bits.data(), recv_buffer.begin(), 8);
if ((recv_buffer[5] & 0x10))
if (recv_buffer[5] & 0x10)
m_supports_extensions = true;
#endif
if (recv_buffer[7] & 0x01)

View File

@ -55,25 +55,22 @@ namespace libtorrent {
std::shared_ptr<torrent> t2 = rhs->associated_torrent().lock();
TORRENT_ASSERT(t2);
int prio1 = lhs->get_priority(peer_connection::upload_channel);
int prio2 = rhs->get_priority(peer_connection::upload_channel);
int const prio1 = lhs->get_priority(peer_connection::upload_channel);
int const prio2 = rhs->get_priority(peer_connection::upload_channel);
if (prio1 != prio2)
return prio1 > prio2;
if (prio1 != prio2) return prio1 > prio2;
// compare how many bytes they've sent us
std::int64_t c1;
std::int64_t c2;
c1 = lhs->downloaded_in_last_round();
c2 = rhs->downloaded_in_last_round();
std::int64_t const d1 = lhs->downloaded_in_last_round();
std::int64_t const d2 = rhs->downloaded_in_last_round();
if (c1 != c2) return c1 > c2;
if (d1 != d2) return d1 > d2;
// when seeding, rotate which peer is unchoked in a round-robin fasion
// the amount uploaded since unchoked (not just in the last round)
c1 = lhs->uploaded_since_unchoked();
c2 = rhs->uploaded_since_unchoked();
std::int64_t const u1 = lhs->uploaded_since_unchoked();
std::int64_t const u2 = rhs->uploaded_since_unchoked();
// the way the round-robin unchoker works is that it,
// by default, prioritizes any peer that is already unchoked.
@ -84,17 +81,17 @@ namespace libtorrent {
// if a peer is already unchoked, the number of bytes sent since it was unchoked
// is greater than the send quanta, and it has been unchoked for at least one minute
// then it's done with its upload slot, and we can de-prioritize it
bool c1_quota_complete = !lhs->is_choked()
&& c1 > t1->torrent_file().piece_length() * pieces
bool const c1_quota_complete = !lhs->is_choked()
&& u1 > t1->torrent_file().piece_length() * pieces
&& aux::time_now() - lhs->time_of_last_unchoke() > minutes(1);
bool c2_quota_complete = !rhs->is_choked()
&& c2 > t2->torrent_file().piece_length() * pieces
bool const c2_quota_complete = !rhs->is_choked()
&& u2 > t2->torrent_file().piece_length() * pieces
&& aux::time_now() - rhs->time_of_last_unchoke() > minutes(1);
// if c2 has completed a quanta, it should be de-prioritized
// and vice versa
if (c1_quota_complete < c2_quota_complete) return true;
if (c1_quota_complete > c2_quota_complete) return false;
if (c1_quota_complete != c2_quota_complete)
return int(c1_quota_complete) < int(c2_quota_complete);
// when seeding, prefer the peer we're uploading the fastest to
@ -103,11 +100,10 @@ namespace libtorrent {
// there may have been a residual transfer which was already
// in-flight at the time and we don't want that to cause the peer
// to be ranked at the top of the choked peers
c1 = lhs->is_choked() ? 0 : lhs->uploaded_in_last_round();
c2 = rhs->is_choked() ? 0 : rhs->uploaded_in_last_round();
std::int64_t const c1 = lhs->is_choked() ? 0 : lhs->uploaded_in_last_round();
std::int64_t const c2 = rhs->is_choked() ? 0 : rhs->uploaded_in_last_round();
if (c1 > c2) return true;
if (c2 > c1) return false;
if (c1 != c2) return c1 > c2;
// if the peers are still identical (say, they're both waiting to be unchoked)
// prioritize the one that has waited the longest to be unchoked

View File

@ -312,7 +312,7 @@ namespace {
create_torrent::create_torrent(file_storage& fs, int piece_size
, int pad_file_limit, create_flags_t const flags, int alignment)
: m_files(fs)
, m_creation_date(time(nullptr))
, m_creation_date(::time(nullptr))
, m_multifile(fs.num_files() > 1)
, m_private(false)
, m_merkle_torrent(bool(flags & create_torrent::merkle))
@ -372,7 +372,7 @@ namespace {
create_torrent::create_torrent(torrent_info const& ti)
: m_files(const_cast<file_storage&>(ti.files()))
, m_creation_date(time(0))
, m_creation_date(::time(0))
, m_multifile(ti.num_files() > 1)
, m_private(ti.priv())
, m_merkle_torrent(ti.is_merkle_torrent())

View File

@ -42,6 +42,7 @@ namespace libtorrent {
disk_buffer_holder& disk_buffer_holder::operator=(disk_buffer_holder&& h) noexcept
{
if (&h == this) return *this;
disk_buffer_holder(std::move(h)).swap(*this);
return *this;
}

View File

@ -170,6 +170,7 @@ namespace libtorrent {
{ rhs.m_lock = nullptr; }
scoped_unlocker_impl& operator=(scoped_unlocker_impl&& rhs)
{
if (&rhs == this) return *this;
if (m_lock) m_lock->lock();
m_lock = rhs.m_lock;
rhs.m_lock = nullptr;
@ -445,6 +446,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
continue;
}
#if DEBUG_DISK_THREAD
if (pe->num_dirty < pe->blocks_in_piece)
{
DLOG("[%d dirty:%d] ", static_cast<int>(i), int(pe->num_dirty));
@ -457,6 +459,7 @@ constexpr disk_job_flags_t disk_interface::cache_hit;
{
DLOG("[%d xx] ", static_cast<int>(i));
}
#endif
// TODO: in this case, the piece should probably not be flushed yet. are there
// any more cases where it should?

View File

@ -61,7 +61,7 @@ namespace detail {
}
buf[--size] = '\0';
if (val == 0) buf[--size] = '0';
for (; size > sign && val != 0;)
while (size > sign && val != 0)
{
buf[--size] = '0' + char(val % 10);
val /= 10;
@ -147,6 +147,7 @@ namespace {
entry& entry::operator=(entry&& e) noexcept
{
if (&e == this) return *this;
swap(e);
return *this;
}

View File

@ -74,7 +74,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <netinet/ether.h>
#include <netinet/in.h>
#include <net/if.h>
#include <stdio.h>
#include <cstdio>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@ -216,7 +216,7 @@ namespace {
// first byte of routing messages is always the family
msg[sizeof(nlmsghdr)] = family;
if (send(sock, nl_msg, nl_msg->nlmsg_len, 0) < 0)
if (::send(sock, nl_msg, nl_msg->nlmsg_len, 0) < 0)
{
return -1;
}
@ -224,7 +224,7 @@ namespace {
// get the socket's port ID so that we can verify it in the repsonse
sockaddr_nl sock_addr;
socklen_t sock_addr_len = sizeof(sock_addr);
if (getsockname(sock, reinterpret_cast<sockaddr*>(&sock_addr), &sock_addr_len) < 0)
if (::getsockname(sock, reinterpret_cast<sockaddr*>(&sock_addr), &sock_addr_len) < 0)
{
return -1;
}
@ -285,10 +285,10 @@ namespace {
#endif
ifreq req = {};
if_indextoname(std::uint32_t(if_index), req.ifr_name);
::if_indextoname(std::uint32_t(if_index), req.ifr_name);
static_assert(sizeof(rt_info->name) >= sizeof(req.ifr_name), "ip_route::name is too small");
std::memcpy(rt_info->name, req.ifr_name, sizeof(req.ifr_name));
ioctl(s, siocgifmtu, &req);
::ioctl(s, ::siocgifmtu, &req);
rt_info->mtu = req.ifr_mtu;
// obviously this doesn't work correctly. How do you get the netmask for a route?
// if (ioctl(s, SIOCGIFNETMASK, &req) == 0) {
@ -549,7 +549,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
ret.push_back(wan);
}
#elif TORRENT_USE_NETLINK
int sock = socket(PF_ROUTE, SOCK_DGRAM, NETLINK_ROUTE);
int sock = ::socket(PF_ROUTE, SOCK_DGRAM, NETLINK_ROUTE);
if (sock < 0)
{
ec = error_code(errno, system_category());
@ -562,7 +562,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (len < 0)
{
ec = error_code(errno, system_category());
close(sock);
::close(sock);
return ret;
}
@ -581,9 +581,9 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
#pragma clang diagnostic pop
#endif
close(sock);
::close(sock);
#elif TORRENT_USE_IFADDRS
int s = socket(AF_INET, SOCK_DGRAM, 0);
int s = ::socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
ec = error_code(errno, system_category());
@ -594,7 +594,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (getifaddrs(&ifaddr) == -1)
{
ec = error_code(errno, system_category());
close(s);
::close(s);
return ret;
}
@ -610,11 +610,11 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
ret.push_back(iface);
}
}
close(s);
::close(s);
freeifaddrs(ifaddr);
// MacOS X, BSD and solaris
#elif TORRENT_USE_IFCONF
int s = socket(AF_INET, SOCK_DGRAM, 0);
int s = ::socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
ec = error_code(errno, system_category());
@ -628,7 +628,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
{
ec = error_code(errno, system_category());
close(s);
::close(s);
return ret;
}
@ -669,7 +669,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
#endif
{
ec = error_code(errno, system_category());
close(s);
::close(s);
return ret;
}
}
@ -683,7 +683,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
ifr += current_size;
remaining -= current_size;
}
close(s);
::close(s);
#elif TORRENT_USE_GETADAPTERSADDRESSES
@ -736,7 +736,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
}
#endif
SOCKET s = socket(AF_INET, SOCK_DGRAM, 0);
SOCKET s = ::socket(AF_INET, SOCK_DGRAM, 0);
if (int(s) == SOCKET_ERROR)
{
ec = error_code(WSAGetLastError(), system_category());
@ -855,7 +855,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
m.m_rtm.rtm_seq = 0;
m.m_rtm.rtm_msglen = len;
int s = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
int s = ::socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
if (s == -1)
{
ec = error_code(errno, system_category());
@ -866,13 +866,13 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (n == -1)
{
ec = error_code(errno, system_category());
close(s);
::close(s);
return std::vector<ip_route>();
}
else if (n != len)
{
ec = boost::asio::error::operation_not_supported;
close(s);
::close(s);
return std::vector<ip_route>();
}
bzero(&m, len);
@ -881,7 +881,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (n == -1)
{
ec = error_code(errno, system_category());
close(s);
::close(s);
return std::vector<ip_route>();
}
@ -936,7 +936,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
r.netmask = sockaddr_to_address((sockaddr*)p);
ret.push_back(r);
}
close(s);
::close(s);
*/
int mib[6] = {CTL_NET, PF_ROUTE, 0, AF_UNSPEC, NET_RT_DUMP, 0};
@ -975,7 +975,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
char* end = buf.get() + needed;
int s = socket(AF_INET, SOCK_DGRAM, 0);
int s = ::socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
ec = error_code(errno, system_category());
@ -995,7 +995,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
ip_route r;
if (parse_route(s, rtm, &r)) ret.push_back(r);
}
close(s);
::close(s);
#elif TORRENT_USE_GETIPFORWARDTABLE
/*
@ -1142,7 +1142,7 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
// Free memory
free(routes);
#elif TORRENT_USE_NETLINK
int sock = socket(PF_ROUTE, SOCK_DGRAM, NETLINK_ROUTE);
int sock = ::socket(PF_ROUTE, SOCK_DGRAM, NETLINK_ROUTE);
if (sock < 0)
{
ec = error_code(errno, system_category());
@ -1157,11 +1157,11 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
if (len < 0)
{
ec = error_code(errno, system_category());
close(sock);
::close(sock);
return std::vector<ip_route>();
}
int s = socket(AF_INET, SOCK_DGRAM, 0);
int s = ::socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
{
ec = error_code(errno, system_category());
@ -1181,8 +1181,8 @@ int _System __libsocket_sysctl(int* mib, u_int namelen, void *oldp, size_t *oldl
#ifdef __clang__
#pragma clang diagnostic pop
#endif
close(s);
close(sock);
::close(s);
::close(sock);
#endif
return ret;

View File

@ -560,7 +560,7 @@ namespace {
// posix has a weird iconv signature. implementations
// differ on what this signature should be, so we use
// a macro to let config.hpp determine it
size_t retval = iconv(h, TORRENT_ICONV_ARG(&in), &insize,
size_t retval = ::iconv(h, TORRENT_ICONV_ARG(&in), &insize,
&out, &outsize);
if (retval == size_t(-1)) return s;
// if this string has an invalid utf-8 sequence in it, don't touch it
@ -581,7 +581,7 @@ namespace {
std::lock_guard<std::mutex> l(iconv_mutex);
// the empty string represents the local dependent encoding
static iconv_t iconv_handle = iconv_open("", "UTF-8");
static iconv_t iconv_handle = ::iconv_open("", "UTF-8");
if (iconv_handle == iconv_t(-1)) return s;
return iconv_convert_impl(s, iconv_handle);
}
@ -593,7 +593,7 @@ namespace {
std::lock_guard<std::mutex> l(iconv_mutex);
// the empty string represents the local dependent encoding
static iconv_t iconv_handle = iconv_open("UTF-8", "");
static iconv_t iconv_handle = ::iconv_open("UTF-8", "");
if (iconv_handle == iconv_t(-1)) return s;
return iconv_convert_impl(s, iconv_handle);
}

View File

@ -381,7 +381,7 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
if (m_handle != INVALID_HANDLE_VALUE)
FindClose(m_handle);
#else
if (m_handle) closedir(m_handle);
if (m_handle) ::closedir(m_handle);
#endif
}
@ -638,11 +638,11 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
if ((mode & open_mode::no_cache))
{
int yes = 1;
fcntl(native_handle(), F_NOCACHE, &yes);
::fcntl(native_handle(), F_NOCACHE, &yes);
#ifdef F_NODIRECT
// it's OK to temporarily cache written pages
fcntl(native_handle(), F_NODIRECT, &yes);
::fcntl(native_handle(), F_NODIRECT, &yes);
#endif
}
#endif
@ -651,7 +651,7 @@ static_assert(!(open_mode::sparse & open_mode::attribute_mask), "internal flags
if ((mode & open_mode::random_access))
{
// disable read-ahead
posix_fadvise(native_handle(), 0, 0, POSIX_FADV_RANDOM);
::posix_fadvise(native_handle(), 0, 0, POSIX_FADV_RANDOM);
}
#endif
@ -1048,7 +1048,7 @@ namespace {
!defined DIRECTIO_ON
if (m_open_mode & open_mode::no_cache)
{
if (fdatasync(native_handle()) != 0
if (::fdatasync(native_handle()) != 0
&& errno != EINVAL
&& errno != ENOSYS)
{
@ -1197,7 +1197,7 @@ namespace {
#endif // if Windows Vista
#else // NON-WINDOWS
struct stat st;
if (fstat(native_handle(), &st) != 0)
if (::fstat(native_handle(), &st) != 0)
{
ec.assign(errno, system_category());
return false;
@ -1205,7 +1205,7 @@ namespace {
// only truncate the file if it doesn't already
// have the right size. We don't want to update
if (st.st_size != s && ftruncate(native_handle(), s) < 0)
if (st.st_size != s && ::ftruncate(native_handle(), s) < 0)
{
ec.assign(errno, system_category());
return false;
@ -1286,7 +1286,7 @@ namespace {
return file_size.QuadPart;
#else
struct stat fs;
if (fstat(native_handle(), &fs) != 0)
if (::fstat(native_handle(), &fs) != 0)
{
ec.assign(errno, system_category());
return -1;
@ -1338,7 +1338,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
#elif defined SEEK_DATA
// this is supported on solaris
std::int64_t ret = lseek(native_handle(), start, SEEK_DATA);
std::int64_t ret = ::lseek(native_handle(), start, SEEK_DATA);
if (ret < 0) return start;
return start;
#else

View File

@ -216,7 +216,7 @@ namespace {
internal_file_entry::~internal_file_entry()
{
if (name_len == name_is_owned) free(const_cast<char*>(name));
if (name_len == name_is_owned) ::free(const_cast<char*>(name));
}
internal_file_entry::internal_file_entry(internal_file_entry const& fe)
@ -240,6 +240,7 @@ namespace {
internal_file_entry& internal_file_entry::operator=(internal_file_entry const& fe)
{
if (&fe == this) return *this;
offset = fe.offset;
size = fe.size;
path_index = fe.path_index;
@ -272,6 +273,7 @@ namespace {
internal_file_entry& internal_file_entry::operator=(internal_file_entry&& fe) noexcept
{
if (&fe == this) return *this;
offset = fe.offset;
size = fe.size;
path_index = fe.path_index;
@ -303,7 +305,7 @@ namespace {
if (string_len >= name_is_owned) string_len = name_is_owned - 1;
// free the current string, before assigning the new one
if (name_len == name_is_owned) free(const_cast<char*>(name));
if (name_len == name_is_owned) ::free(const_cast<char*>(name));
if (n == nullptr)
{
TORRENT_ASSERT(borrow_string == false);

View File

@ -642,7 +642,7 @@ void http_connection::callback(error_code e, span<char> data)
data = m_parser.collapse_chunk_headers(data);
std::string const& encoding = m_parser.header("content-encoding");
if ((encoding == "gzip" || encoding == "x-gzip"))
if (encoding == "gzip" || encoding == "x-gzip")
{
error_code ec;
inflate_gzip(data, buf, m_max_bottled_buffer_size, ec);

View File

@ -445,8 +445,6 @@ namespace libtorrent {
, std::bind(&i2p_stream::read_line, this, _1, h));
break;
}
return;
}
void i2p_stream::send_connect(handler_type h)

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cctype>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/optional.hpp>
@ -45,7 +46,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace {
using namespace libtorrent;
int decode_digit(std::uint8_t c)
@ -138,7 +138,7 @@ namespace {
// only support BitTorrentSpecification
// must be ordered alphabetically
static const map_entry name_map[] =
const map_entry name_map[] =
{
{"7T", "aTorrent for android"}
, {"A", "ABC"}
@ -244,7 +244,7 @@ namespace {
char const* name;
};
// non-standard names
static const generic_map_entry generic_mappings[] =
const generic_map_entry generic_mappings[] =
{
{0, "Deadman Walking-", "Deadman"}
, {5, "Azureus", "Azureus 2.0.3.2"}
@ -290,9 +290,7 @@ namespace {
|| ((lhs.id[0] == rhs.id[0]) && (lhs.id[1] < rhs.id[1]));
}
namespace {
static std::string lookup(fingerprint const& f)
std::string lookup(fingerprint const& f)
{
char identity[200];
@ -320,7 +318,7 @@ namespace {
{
// if we don't have this client in the list
// just use the one or two letter code
memcpy(temp, f.name, 2);
std::memcpy(temp, f.name, 2);
temp[2] = 0;
name = temp;
}
@ -336,12 +334,13 @@ namespace {
return identity;
}
}
bool find_string(char const* id, char const* search)
{
return std::equal(search, search + std::strlen(search), id);
}
}
} // anonymous namespace
namespace libtorrent {

View File

@ -183,7 +183,7 @@ namespace {
int count() const { return int(samples.size()); }
};
class dht_default_storage final : public dht_storage_interface, boost::noncopyable
class dht_default_storage final : public dht_storage_interface
{
public:
@ -195,6 +195,9 @@ namespace {
~dht_default_storage() override = default;
dht_default_storage(dht_default_storage const&) = delete;
dht_default_storage& operator=(dht_default_storage const&) = delete;
#ifndef TORRENT_NO_DEPRECATE
size_t num_torrents() const override { return m_map.size(); }
size_t num_peers() const override
@ -558,7 +561,7 @@ namespace {
m_counters.peers -= std::int32_t(std::distance(new_end, peers.end()));
peers.erase(new_end, peers.end());
// if we're using less than 1/4 of the capacity free up the excess
if (!peers.empty() && peers.capacity() / peers.size() >= 4u)
if (!peers.empty() && peers.capacity() / peers.size() >= 4U)
peers.shrink_to_fit();
}

View File

@ -1183,7 +1183,6 @@ void node::incoming_request(msg const& m, entry& e)
sha1_hash const target(target_ent.string_ptr());
// always return nodes as well as peers
write_nodes_entries(target, arg_ent.dict_find_list("want"), reply);
return;
}
}

View File

@ -61,9 +61,9 @@ void put_data::set_targets(std::vector<std::pair<node_entry, std::string>> const
, p.first.id, p.second);
if (!o) return;
#if TORRENT_USE_ASSERTS
#if TORRENT_USE_ASSERTS
o->m_in_constructor = false;
#endif
#endif
m_results.push_back(std::move(o));
}
}

View File

@ -36,7 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/lazy_entry.hpp"
#include "libtorrent/bdecode.hpp" // for error codes
#include "libtorrent/string_util.hpp" // for is_digit
#include <cstring>
#include <cstring> // for memset
#include <limits> // for numeric_limits
#include <cstdio> // for snprintf
#include <cinttypes> // for PRId64 et.al.
@ -241,10 +241,9 @@ namespace {
{
TORRENT_ASSERT(m_type == int_t);
std::int64_t val = 0;
bool negative = false;
if (*m_data.start == '-') negative = true;
bool const negative = (*m_data.start == '-');
bdecode_errors::error_code_enum ec = bdecode_errors::no_error;
parse_int(m_data.start + negative
parse_int(m_data.start + int(negative)
, m_data.start + m_size, 'e', val, ec);
if (ec) return 0;
if (negative) val = -val;
@ -605,7 +604,7 @@ namespace {
std::string print_entry(lazy_entry const& e, bool single_line, int indent)
{
char indent_str[200];
memset(indent_str, ' ', 200);
std::memset(indent_str, ' ', 200);
indent_str[0] = ',';
indent_str[1] = '\n';
indent_str[199] = 0;

View File

@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <cinttypes> // for PRId64 et.al.
#include <cstdarg>
#include <functional>
#include <cstring> // for memcpy
#include "libtorrent/natpmp.hpp"
#include "libtorrent/io.hpp"
@ -434,7 +435,7 @@ void natpmp::on_reply(error_code const& e
// make a copy of the response packet buffer
// to avoid overwriting it in the next receive call
char msg_buf[sizeof(m_response_buffer)];
memcpy(msg_buf, m_response_buffer, bytes_transferred);
std::memcpy(msg_buf, m_response_buffer, bytes_transferred);
m_socket.async_receive_from(boost::asio::buffer(&m_response_buffer[0]
, sizeof(m_response_buffer))

View File

@ -4065,7 +4065,6 @@ namespace libtorrent {
#endif
disconnect(e, operation_t::connect, 1);
return;
}
// the error argument defaults to 0, which means deliberate disconnect

View File

@ -1347,10 +1347,10 @@ namespace libtorrent {
// prefer to drop peers whose only source is resume data
if (lhs_resume_data_source != rhs_resume_data_source)
return lhs_resume_data_source > rhs_resume_data_source;
return int(lhs_resume_data_source) > int(rhs_resume_data_source);
if (lhs.connectable != rhs.connectable)
return lhs.connectable < rhs.connectable;
return int(lhs.connectable) < int(rhs.connectable);
return lhs.trust_points < rhs.trust_points;
}
@ -1365,9 +1365,9 @@ namespace libtorrent {
return lhs->failcount < rhs->failcount;
// Local peers should always be tried first
bool lhs_local = is_local(lhs->address());
bool rhs_local = is_local(rhs->address());
if (lhs_local != rhs_local) return lhs_local > rhs_local;
bool const lhs_local = is_local(lhs->address());
bool const rhs_local = is_local(rhs->address());
if (lhs_local != rhs_local) return int(lhs_local) > int(rhs_local);
if (lhs->last_connected != rhs->last_connected)
return lhs->last_connected < rhs->last_connected;
@ -1376,9 +1376,8 @@ namespace libtorrent {
int const rhs_rank = source_rank(rhs->peer_source());
if (lhs_rank != rhs_rank) return lhs_rank > rhs_rank;
std::uint32_t lhs_peer_rank = lhs->rank(external, external_port);
std::uint32_t rhs_peer_rank = rhs->rank(external, external_port);
if (lhs_peer_rank > rhs_peer_rank) return true;
return false;
std::uint32_t const lhs_peer_rank = lhs->rank(external, external_port);
std::uint32_t const rhs_peer_rank = rhs->rank(external, external_port);
return lhs_peer_rank > rhs_peer_rank;
}
}

View File

@ -61,6 +61,7 @@ namespace libtorrent {
counters& counters::operator=(counters const& c)
{
if (&c == this) return *this;
#ifdef ATOMIC_LLONG_LOCK_FREE
for (int i = 0; i < m_stats_counter.end_index(); ++i)
m_stats_counter[i].store(

View File

@ -6708,10 +6708,9 @@ namespace libtorrent {
bool connecting_time_compare(peer_connection const* lhs, peer_connection const* rhs)
{
bool lhs_connecting = lhs->is_connecting() && !lhs->is_disconnecting();
bool rhs_connecting = rhs->is_connecting() && !rhs->is_disconnecting();
if (lhs_connecting > rhs_connecting) return false;
if (lhs_connecting < rhs_connecting) return true;
bool const lhs_connecting = lhs->is_connecting() && !lhs->is_disconnecting();
bool const rhs_connecting = rhs->is_connecting() && !rhs->is_disconnecting();
if (lhs_connecting != rhs_connecting) return (lhs_connecting < rhs_connecting);
// a lower value of connected_time means it's been waiting
// longer. This is a less-than comparison, so if lhs has
@ -7770,8 +7769,7 @@ namespace libtorrent {
else if (m_state == torrent_status::downloading_metadata
|| m_state == torrent_status::downloading
|| m_state == torrent_status::finished
|| m_state == torrent_status::seeding
|| m_state == torrent_status::downloading)
|| m_state == torrent_status::seeding)
{
if (is_finished())
is_seeding = true;