From e2487c4d248462152bab464645793075d24d3960 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Mon, 29 Aug 2016 08:31:23 -0400 Subject: [PATCH] more use of std::shared_ptr refactor --- include/libtorrent/aux_/session_impl.hpp | 8 ++--- include/libtorrent/block_cache.hpp | 10 +++--- include/libtorrent/disk_io_job.hpp | 16 +++------- .../libtorrent/http_tracker_connection.hpp | 4 +-- include/libtorrent/kademlia/dht_tracker.hpp | 5 ++- include/libtorrent/lsd.hpp | 19 ++--------- include/libtorrent/natpmp.hpp | 14 ++------ include/libtorrent/receive_buffer.hpp | 2 ++ include/libtorrent/storage.hpp | 5 +-- include/libtorrent/torrent.hpp | 2 +- include/libtorrent/tracker_manager.hpp | 15 ++++----- include/libtorrent/udp_socket.hpp | 3 +- include/libtorrent/udp_tracker_connection.hpp | 4 +-- include/libtorrent/upnp.hpp | 5 ++- src/create_torrent.cpp | 4 +-- src/disk_io_job.cpp | 5 +-- src/disk_io_thread.cpp | 2 +- src/http_tracker_connection.cpp | 2 +- src/kademlia/dht_tracker.cpp | 32 +++++++------------ src/lsd.cpp | 2 -- src/natpmp.cpp | 2 -- src/session_impl.cpp | 10 +++--- src/torrent.cpp | 2 +- src/tracker_manager.cpp | 30 ++++++++--------- src/udp_socket.cpp | 13 ++++---- src/upnp.cpp | 16 ++++------ test/test_bandwidth_limiter.cpp | 15 ++++----- test/test_block_cache.cpp | 2 +- test/test_storage.cpp | 3 +- test/test_upnp.cpp | 4 +-- 30 files changed, 97 insertions(+), 159 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 003e3ca32..1ef8657c4 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1009,7 +1009,7 @@ namespace libtorrent #ifndef TORRENT_DISABLE_DHT std::unique_ptr m_dht_storage; - boost::shared_ptr m_dht; + std::shared_ptr m_dht; dht_settings m_dht_settings; dht::dht_storage_constructor_type m_dht_storage_constructor = dht::dht_default_storage_constructor; @@ -1068,9 +1068,9 @@ namespace libtorrent // this is deducted from the connect speed int m_boost_connections = 0; - boost::shared_ptr m_natpmp; - boost::shared_ptr m_upnp; - boost::shared_ptr m_lsd; + std::shared_ptr m_natpmp; + std::shared_ptr m_upnp; + std::shared_ptr m_lsd; // mask is a bitmask of which protocols to remap on: // 1: NAT-PMP diff --git a/include/libtorrent/block_cache.hpp b/include/libtorrent/block_cache.hpp index b49a7c32b..7bbf6641a 100644 --- a/include/libtorrent/block_cache.hpp +++ b/include/libtorrent/block_cache.hpp @@ -36,14 +36,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include -#include #include -#include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" +#include +#include +#include + #include "libtorrent/time.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/io_service_fwd.hpp" @@ -187,7 +187,7 @@ namespace libtorrent } // storage this piece belongs to - boost::shared_ptr storage; + std::shared_ptr storage; // write jobs hanging off of this piece tailqueue jobs; diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index f6e8d0451..85ef7abf0 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -33,26 +33,18 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_DISK_IO_JOB_HPP #define TORRENT_DISK_IO_JOB_HPP -#include "libtorrent/time.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/tailqueue.hpp" -#include "libtorrent/peer_id.hpp" #include - -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" +#include +#include +#include namespace libtorrent { - class entry; class piece_manager; struct cached_piece_entry; - struct bdecode_node; class torrent_info; struct add_torrent_params; @@ -161,7 +153,7 @@ namespace libtorrent } buffer; // the disk storage this job applies to (if applicable) - boost::shared_ptr storage; + std::shared_ptr storage; // this is called when operation completes std::function callback; diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index 7abf1ed06..a8dc1bef7 100644 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -77,9 +77,9 @@ namespace libtorrent private: - boost::shared_ptr shared_from_this() + std::shared_ptr shared_from_this() { - return boost::static_pointer_cast( + return std::static_pointer_cast( tracker_connection::shared_from_this()); } diff --git a/include/libtorrent/kademlia/dht_tracker.hpp b/include/libtorrent/kademlia/dht_tracker.hpp index ad6a79045..771efe140 100644 --- a/include/libtorrent/kademlia/dht_tracker.hpp +++ b/include/libtorrent/kademlia/dht_tracker.hpp @@ -36,7 +36,6 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_DHT_TRACKER #include -#include #include "libtorrent/kademlia/node.hpp" #include "libtorrent/kademlia/node_id.hpp" @@ -63,7 +62,7 @@ namespace libtorrent { namespace dht struct TORRENT_EXTRA_EXPORT dht_tracker final : udp_socket_interface - , boost::enable_shared_from_this + , std::enable_shared_from_this { typedef std::function, error_code&, int)> send_fun_t; @@ -134,7 +133,7 @@ namespace libtorrent { namespace dht private: - boost::shared_ptr self() + std::shared_ptr self() { return shared_from_this(); } void connection_timeout(node& n, error_code const& e); diff --git a/include/libtorrent/lsd.hpp b/include/libtorrent/lsd.hpp index a75eaefb1..b19bfba39 100644 --- a/include/libtorrent/lsd.hpp +++ b/include/libtorrent/lsd.hpp @@ -38,19 +38,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/broadcast_socket.hpp" #include "libtorrent/deadline_timer.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include -#include -#include - -#ifndef TORRENT_DISABLE_LOGGING -#include -#endif - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { @@ -59,7 +46,7 @@ typedef std::function peer_callback_t; typedef std::function log_callback_t; #endif -class lsd : public boost::enable_shared_from_this +class lsd : public std::enable_shared_from_this { public: lsd(io_service& ios, peer_callback_t const& cb @@ -76,7 +63,7 @@ public: private: - boost::shared_ptr self() { return shared_from_this(); } + std::shared_ptr self() { return shared_from_this(); } void announce_impl(sha1_hash const& ih, int listen_port , bool broadcast, int retry_count); @@ -117,6 +104,4 @@ private: } - #endif - diff --git a/include/libtorrent/natpmp.hpp b/include/libtorrent/natpmp.hpp index 58e2ef21e..e0af7e48d 100644 --- a/include/libtorrent/natpmp.hpp +++ b/include/libtorrent/natpmp.hpp @@ -41,14 +41,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/time.hpp" #include "libtorrent/debug.hpp" -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - namespace libtorrent { @@ -59,7 +51,7 @@ typedef std::function portmap_c typedef std::function log_callback_t; struct TORRENT_EXTRA_EXPORT natpmp - : boost::enable_shared_from_this + : std::enable_shared_from_this , single_threaded { natpmp(io_service& ios, portmap_callback_t const& cb @@ -78,7 +70,7 @@ struct TORRENT_EXTRA_EXPORT natpmp private: - boost::shared_ptr self() { return shared_from_this(); } + std::shared_ptr self() { return shared_from_this(); } void update_mapping(int i); void send_map_request(int i); @@ -182,6 +174,4 @@ private: } - #endif - diff --git a/include/libtorrent/receive_buffer.hpp b/include/libtorrent/receive_buffer.hpp index 2df220b5a..3c30f132f 100644 --- a/include/libtorrent/receive_buffer.hpp +++ b/include/libtorrent/receive_buffer.hpp @@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +#include + namespace libtorrent { struct TORRENT_EXTRA_EXPORT receive_buffer diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index 301c0fb70..121d63b43 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -43,10 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include -#include #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -554,7 +551,7 @@ namespace libtorrent }; class TORRENT_EXTRA_EXPORT piece_manager - : public boost::enable_shared_from_this + : public std::enable_shared_from_this , public disk_job_fence , public storage_piece_set , boost::noncopyable diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index cab23744a..6ddd453d8 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1167,7 +1167,7 @@ namespace libtorrent // the piece_manager, and stored in the // torrent, so the torrent cannot destruct // before the piece_manager. - boost::shared_ptr m_storage; + std::shared_ptr m_storage; #ifdef TORRENT_USE_OPENSSL boost::shared_ptr m_ssl_ctx; diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 3ff0320b2..eec80827a 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -219,7 +219,7 @@ namespace libtorrent int incomplete; // if supported by the tracker, the number of actively downloading peers. - // i.e. partial seeds. If not suppored, -1 + // i.e. partial seeds. If not supported, -1 int downloaders; // the number of times the torrent has been downloaded @@ -254,7 +254,7 @@ namespace libtorrent }; struct TORRENT_EXTRA_EXPORT timeout_handler - : boost::enable_shared_from_this + : std::enable_shared_from_this , boost::noncopyable { timeout_handler(io_service& str); @@ -315,9 +315,9 @@ namespace libtorrent void sent_bytes(int bytes); void received_bytes(int bytes); - boost::shared_ptr shared_from_this() + std::shared_ptr shared_from_this() { - return boost::static_pointer_cast( + return std::static_pointer_cast( timeout_handler::shared_from_this()); } @@ -383,7 +383,7 @@ namespace libtorrent bool incoming_packet(char const* hostname, span buf); void update_transaction_id( - boost::shared_ptr c + std::shared_ptr c , std::uint64_t tid); aux::session_settings const& settings() const { return m_settings; } @@ -401,10 +401,10 @@ namespace libtorrent // These must use shared_ptr to avoid a dangling reference // if a connection is erased while a timeout event is in the queue typedef boost::unordered_map > udp_conns_t; + , std::shared_ptr> udp_conns_t; udp_conns_t m_udp_conns; - typedef std::vector > http_conns_t; + typedef std::vector> http_conns_t; http_conns_t m_http_conns; send_fun_t m_send_fun; @@ -421,4 +421,3 @@ namespace libtorrent } #endif // TORRENT_TRACKER_MANAGER_HPP_INCLUDED - diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index c33827b65..d3913535d 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -141,7 +141,7 @@ namespace libtorrent aux::proxy_settings m_proxy_settings; - boost::shared_ptr m_socks5_connection; + std::shared_ptr m_socks5_connection; // TODO: 3 add a unit test for force-proxy bool m_force_proxy:1; @@ -155,4 +155,3 @@ namespace libtorrent } #endif - diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp index 58315e2d8..a22a13841 100644 --- a/include/libtorrent/udp_tracker_connection.hpp +++ b/include/libtorrent/udp_tracker_connection.hpp @@ -80,9 +80,9 @@ namespace libtorrent action_error }; - boost::shared_ptr shared_from_this() + std::shared_ptr shared_from_this() { - return boost::static_pointer_cast( + return std::static_pointer_cast( tracker_connection::shared_from_this()); } diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index 0c838ecae..b6bfb5558 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -44,7 +44,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include @@ -131,7 +130,7 @@ TORRENT_EXTRA_EXPORT void find_control_url(int type, char const* string // TODO: support using the windows API for UPnP operations as well struct TORRENT_EXTRA_EXPORT upnp final - : boost::enable_shared_from_this + : std::enable_shared_from_this , single_threaded { upnp(io_service& ios @@ -182,7 +181,7 @@ struct TORRENT_EXTRA_EXPORT upnp final private: - boost::shared_ptr self() { return shared_from_this(); } + std::shared_ptr self() { return shared_from_this(); } void map_timer(error_code const& ec); void try_map_upnp(bool timer = false); diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index ee7b98414..19d66b01f 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -161,7 +161,7 @@ namespace libtorrent } void on_hash(disk_io_job const* j, create_torrent* t - , boost::shared_ptr storage, disk_io_thread* iothread + , std::shared_ptr storage, disk_io_thread* iothread , int* piece_counter, int* completed_piece , std::function const* f, error_code* ec) { @@ -282,7 +282,7 @@ namespace libtorrent storage_interface* storage_impl = default_storage_constructor(params); - boost::shared_ptr storage = boost::make_shared( + std::shared_ptr storage = std::make_shared( storage_impl, dummy, const_cast(&t.files())); settings_pack sett; diff --git a/src/disk_io_job.cpp b/src/disk_io_job.cpp index 768976d62..e2d368a2b 100644 --- a/src/disk_io_job.cpp +++ b/src/disk_io_job.cpp @@ -31,9 +31,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "libtorrent/disk_io_job.hpp" -#include "libtorrent/storage.hpp" #include "libtorrent/block_cache.hpp" // for cached_piece_entry -#include "libtorrent/entry.hpp" namespace libtorrent { @@ -68,7 +66,7 @@ namespace libtorrent { if (action != write) return false; - int block_offset = d.io.offset & (block_size-1); + int block_offset = d.io.offset & (block_size - 1); int size = d.io.buffer_size; int start = d.io.offset / block_size; int end = block_offset > 0 && (size > block_size - block_offset) ? start + 2 : start + 1; @@ -81,4 +79,3 @@ namespace libtorrent return true; } } - diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index ab6a3693e..161f31d4f 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -1074,7 +1074,7 @@ namespace libtorrent } #endif - boost::shared_ptr storage = j->storage; + std::shared_ptr storage = j->storage; // TODO: instead of doing this. pass in the settings to each storage_interface // call. Each disk thread could hold its most recent understanding of the settings diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index e016ee1df..049d9c03c 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -297,7 +297,7 @@ namespace libtorrent , http_parser const& parser, char const* data, int size) { // keep this alive - boost::shared_ptr me(shared_from_this()); + std::shared_ptr me(shared_from_this()); if (ec && ec != boost::asio::error::eof) { diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index fb665a0b0..7d22f1b73 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -56,14 +56,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/hex.hpp" // to_hex #endif -#include "libtorrent/aux_/disable_warnings_push.hpp" - -#include -#include -#include - -#include "libtorrent/aux_/disable_warnings_pop.hpp" - using libtorrent::dht::node; using libtorrent::dht::node_id; using libtorrent::dht::packet_t; @@ -363,7 +355,7 @@ namespace libtorrent { namespace dht // these functions provide a slightly higher level // interface to the get/put functionality in the DHT - void get_immutable_item_callback(item const& it, boost::shared_ptr ctx + void get_immutable_item_callback(item const& it, std::shared_ptr ctx , std::function f) { // the reason to wrap here is to control the return value @@ -385,7 +377,7 @@ namespace libtorrent { namespace dht }; void get_mutable_item_callback(item const& it, bool authoritative - , boost::shared_ptr ctx + , std::shared_ptr ctx , std::function f) { TORRENT_ASSERT(it.is_mutable()); @@ -411,7 +403,7 @@ namespace libtorrent { namespace dht int response_count; }; - void put_immutable_item_callback(int responses, boost::shared_ptr ctx + void put_immutable_item_callback(int responses, std::shared_ptr ctx , std::function f) { ctx->response_count += responses; @@ -419,7 +411,7 @@ namespace libtorrent { namespace dht f(ctx->response_count); } - void put_mutable_item_callback(item const& it, int responses, boost::shared_ptr ctx + void put_mutable_item_callback(item const& it, int responses, std::shared_ptr ctx , std::function cb) { ctx->response_count += responses; @@ -432,8 +424,8 @@ namespace libtorrent { namespace dht void dht_tracker::get_item(sha1_hash const& target , std::function cb) { - boost::shared_ptr - ctx = boost::make_shared((TORRENT_USE_IPV6) ? 2 : 1); + std::shared_ptr + ctx = std::make_shared((TORRENT_USE_IPV6) ? 2 : 1); m_dht.get_item(target, std::bind(&get_immutable_item_callback, _1, ctx, cb)); #if TORRENT_USE_IPV6 m_dht6.get_item(target, std::bind(&get_immutable_item_callback, _1, ctx, cb)); @@ -446,8 +438,8 @@ namespace libtorrent { namespace dht , std::function cb , std::string salt) { - boost::shared_ptr - ctx = boost::make_shared((TORRENT_USE_IPV6) ? 2 : 1); + std::shared_ptr + ctx = std::make_shared((TORRENT_USE_IPV6) ? 2 : 1); m_dht.get_item(key, salt, std::bind(&get_mutable_item_callback, _1, _2, ctx, cb)); #if TORRENT_USE_IPV6 m_dht6.get_item(key, salt, std::bind(&get_mutable_item_callback, _1, _2, ctx, cb)); @@ -461,8 +453,8 @@ namespace libtorrent { namespace dht bencode(std::back_inserter(flat_data), data); sha1_hash const target = item_target_id(flat_data); - boost::shared_ptr - ctx = boost::make_shared((TORRENT_USE_IPV6) ? 2 : 1); + std::shared_ptr + ctx = std::make_shared((TORRENT_USE_IPV6) ? 2 : 1); m_dht.put_item(target, data, std::bind(&put_immutable_item_callback , _1, ctx, cb)); #if TORRENT_USE_IPV6 @@ -475,8 +467,8 @@ namespace libtorrent { namespace dht , std::function cb , std::function data_cb, std::string salt) { - boost::shared_ptr - ctx = boost::make_shared((TORRENT_USE_IPV6) ? 2 : 1); + std::shared_ptr + ctx = std::make_shared((TORRENT_USE_IPV6) ? 2 : 1); m_dht.put_item(key, salt, std::bind(&put_mutable_item_callback , _1, _2, ctx, cb), data_cb); diff --git a/src/lsd.cpp b/src/lsd.cpp index 6f37013a0..b88a83154 100644 --- a/src/lsd.cpp +++ b/src/lsd.cpp @@ -311,5 +311,3 @@ void lsd::close() } } // libtorrent namespace - - diff --git a/src/natpmp.cpp b/src/natpmp.cpp index c63e04073..23059e7a3 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -37,7 +37,6 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif -#include #include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -657,4 +656,3 @@ void natpmp::close_impl() m_currently_mapping = -1; update_mapping(0); } - diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 46da70087..f27b1494e 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5521,11 +5521,11 @@ namespace aux { if (m_outstanding_router_lookups > 0) return; m_dht_storage = m_dht_storage_constructor(m_dht_settings); - m_dht = boost::make_shared( + m_dht = std::make_shared( static_cast(this) , std::ref(m_io_service) , std::bind(&session_impl::send_udp_packet, this, false, _1, _2, _3, _4) - , boost::cref(m_dht_settings) + , std::cref(m_dht_settings) , std::ref(m_stats_counters) , *m_dht_storage , startup_state); @@ -6390,7 +6390,7 @@ namespace aux { if (m_lsd) return; - m_lsd = boost::make_shared(std::ref(m_io_service) + m_lsd = std::make_shared(std::ref(m_io_service) , std::bind(&session_impl::on_lsd_peer, this, _1, _2) #ifndef TORRENT_DISABLE_LOGGING , std::bind(&session_impl::on_lsd_log, this, _1) @@ -6418,7 +6418,7 @@ namespace aux { // the natpmp constructor may fail and call the callbacks // into the session_impl. - m_natpmp = boost::make_shared(std::ref(m_io_service) + m_natpmp = std::make_shared(std::ref(m_io_service) , std::bind(&session_impl::on_port_mapping , this, _1, _2, _3, _4, _5, 0) , std::bind(&session_impl::on_port_map_log @@ -6440,7 +6440,7 @@ namespace aux { if (m_upnp) return m_upnp.get(); // the upnp constructor may fail and call the callbacks - m_upnp = boost::make_shared(std::ref(m_io_service) + m_upnp = std::make_shared(std::ref(m_io_service) , m_settings.get_str(settings_pack::user_agent) , std::bind(&session_impl::on_port_mapping , this, _1, _2, _3, _4, _5, 1) diff --git a/src/torrent.cpp b/src/torrent.cpp index 64e3a54ce..1a413a76b 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1675,7 +1675,7 @@ namespace libtorrent // the shared_from_this() will create an intentional // cycle of ownership, se the hpp file for description. - m_storage = boost::make_shared( + m_storage = std::make_shared( storage_impl, shared_from_this() , const_cast(&m_torrent_file->files())); } diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 6ef90a624..933240803 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -238,7 +238,7 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); http_conns_t::iterator i = std::find_if(m_http_conns.begin(), m_http_conns.end() - , [c] (boost::shared_ptr const& ptr) { return ptr.get() == c; }); + , [c] (std::shared_ptr const& ptr) { return ptr.get() == c; }); if (i != m_http_conns.end()) { m_http_conns.erase(i); @@ -255,7 +255,7 @@ namespace libtorrent } void tracker_manager::update_transaction_id( - boost::shared_ptr c + std::shared_ptr c , std::uint64_t tid) { TORRENT_ASSERT(is_single_thread()); @@ -287,18 +287,18 @@ namespace libtorrent if (protocol == "http") #endif { - boost::shared_ptr con - = boost::make_shared( - std::ref(ios), std::ref(*this), boost::cref(req), c); + std::shared_ptr con + = std::make_shared( + std::ref(ios), std::ref(*this), std::cref(req), c); m_http_conns.push_back(con); con->start(); return; } else if (protocol == "udp") { - boost::shared_ptr con - = boost::make_shared( - std::ref(ios), std::ref(*this), boost::cref(req) , c); + std::shared_ptr con + = std::make_shared( + std::ref(ios), std::ref(*this), std::cref(req) , c); m_udp_conns[con->transaction_id()] = con; con->start(); return; @@ -344,7 +344,7 @@ namespace libtorrent return false; } - boost::shared_ptr const p = i->second; + std::shared_ptr const p = i->second; // on_receive() may remove the tracker connection from the list return p->on_receive(ep, buf); } @@ -383,7 +383,7 @@ namespace libtorrent return false; } - boost::shared_ptr const p = i->second; + std::shared_ptr const p = i->second; // on_receive() may remove the tracker connection from the list return p->on_receive_hostname(hostname, buf); } @@ -412,7 +412,7 @@ namespace libtorrent m_abort = true; http_conns_t close_http_connections; - std::vector > close_udp_connections; + std::vector> close_udp_connections; for (http_conns_t::iterator i = m_http_conns.begin() , end(m_http_conns.end()); i != end; ++i) @@ -432,7 +432,7 @@ namespace libtorrent for (udp_conns_t::iterator i = m_udp_conns.begin() , end(m_udp_conns.end()); i != end; ++i) { - boost::shared_ptr c = i->second; + std::shared_ptr c = i->second; tracker_request const& req = c->tracker_req(); if (req.event == tracker_request::stopped && !all) continue; @@ -451,11 +451,9 @@ namespace libtorrent (*i)->close(); } - for (std::vector >::iterator i - = close_udp_connections.begin() - , end(close_udp_connections.end()); i != end; ++i) + for (auto const& c : close_udp_connections) { - (*i)->close(); + c->close(); } } diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index 54933b0a8..2981d1e90 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -41,12 +41,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/debug.hpp" #include +#include +#include #include "libtorrent/aux_/disable_warnings_push.hpp" -#include -#include -#include #include #include #include @@ -66,7 +65,7 @@ using namespace std::placeholders; // been destructed, it needs to be held by a shared_ptr // 2. since using a socks proxy is assumed to be a less common case, it makes // the common case cheaper by not allocating this space unconditionally -struct socks5 : boost::enable_shared_from_this +struct socks5 : std::enable_shared_from_this { explicit socks5(io_service& ios) : m_socks5_sock(ios) @@ -75,7 +74,7 @@ struct socks5 : boost::enable_shared_from_this , m_abort(false) , m_active(false) { - memset(m_tmp_buf, 0, sizeof(m_tmp_buf)); + std::memset(m_tmp_buf, 0, sizeof(m_tmp_buf)); } void start(aux::proxy_settings const& ps); @@ -86,7 +85,7 @@ struct socks5 : boost::enable_shared_from_this private: - boost::shared_ptr self() { return shared_from_this(); } + std::shared_ptr self() { return shared_from_this(); } void on_name_lookup(error_code const& e, tcp::resolver::iterator i); void on_connect_timeout(error_code const& ec); @@ -478,7 +477,7 @@ void udp_socket::set_proxy_settings(aux::proxy_settings const& ps) { // connect to socks5 server and open up the UDP tunnel - m_socks5_connection = boost::make_shared(std::ref(m_socket.get_io_service())); + m_socks5_connection = std::make_shared(std::ref(m_socket.get_io_service())); m_socks5_connection->start(ps); } } diff --git a/src/upnp.cpp b/src/upnp.cpp index 52f32c37a..94c2b0c87 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/debug.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp" -#include #include #include #include "libtorrent/aux_/disable_warnings_pop.hpp" @@ -274,7 +273,7 @@ void upnp::resend_request(error_code const& ec) COMPLETE_ASYNC("upnp::resend_request"); if (ec) return; - boost::shared_ptr me(self()); + std::shared_ptr me(self()); if (m_closing) return; @@ -332,7 +331,7 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer , std::size_t bytes_transferred) { TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr me(self()); + std::shared_ptr me(self()); using namespace libtorrent::detail; @@ -739,7 +738,7 @@ void upnp::update_map(rootdevice& d, int i) if (d.upnp_connection) return; - boost::shared_ptr me(self()); + std::shared_ptr me(self()); mapping_t& m = d.mapping[i]; @@ -900,7 +899,7 @@ void upnp::on_upnp_xml(error_code const& e , http_connection& c) { TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr me(self()); + std::shared_ptr me(self()); TORRENT_ASSERT(d.magic == 1337); if (d.upnp_connection && d.upnp_connection.get() == &c) @@ -1181,7 +1180,7 @@ void upnp::on_upnp_get_ip_address_response(error_code const& e , http_connection& c) { TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr me(self()); + std::shared_ptr me(self()); TORRENT_ASSERT(d.magic == 1337); if (d.upnp_connection && d.upnp_connection.get() == &c) @@ -1267,7 +1266,7 @@ void upnp::on_upnp_map_response(error_code const& e , http_connection& c) { TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr me(self()); + std::shared_ptr me(self()); TORRENT_ASSERT(d.magic == 1337); if (d.upnp_connection && d.upnp_connection.get() == &c) @@ -1434,7 +1433,7 @@ void upnp::on_upnp_unmap_response(error_code const& e , http_connection& c) { TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr me(self()); + std::shared_ptr me(self()); TORRENT_ASSERT(d.magic == 1337); if (d.upnp_connection && d.upnp_connection.get() == &c) @@ -1562,4 +1561,3 @@ void upnp::close() } } - diff --git a/test/test_bandwidth_limiter.cpp b/test/test_bandwidth_limiter.cpp index 764e47c40..635063353 100644 --- a/test/test_bandwidth_limiter.cpp +++ b/test/test_bandwidth_limiter.cpp @@ -43,7 +43,6 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_push.hpp" #include -#include #include "libtorrent/aux_/disable_warnings_pop.hpp" #include @@ -117,7 +116,7 @@ void peer_connection::start() } -typedef std::vector > connections_t; +typedef std::vector> connections_t; void do_change_rate(bandwidth_channel& t1, bandwidth_channel& t2, int limit) { @@ -184,7 +183,7 @@ void spawn_connections(connections_t& v, bandwidth_manager& bwm { char name[200]; std::snprintf(name, sizeof(name), "%s%d", prefix, i); - v.push_back(boost::shared_ptr(new peer_connection(bwm, bwc, 200, false, name))); + v.push_back(boost::make_shared(bwm, bwc, 200, false, name)); } } @@ -404,8 +403,8 @@ void test_peer_priority(int limit, bool torrent_limit) spawn_connections(v1, manager, t1, 10, "p"); connections_t v; std::copy(v1.begin(), v1.end(), std::back_inserter(v)); - boost::shared_ptr p( - new peer_connection(manager, t1, 1, false, "no-priority")); + boost::shared_ptr p = + boost::make_shared(manager, t1, 1, false, "no-priority"); v.push_back(p); run_test(v, manager); @@ -440,8 +439,8 @@ void test_no_starvation(int limit) spawn_connections(v1, manager, t1, num_peers, "p"); connections_t v; std::copy(v1.begin(), v1.end(), std::back_inserter(v)); - boost::shared_ptr p( - new peer_connection(manager, t2, 1, false, "no-priority")); + boost::shared_ptr p = + boost::make_shared(manager, t2, 1, false, "no-priority"); v.push_back(p); run_test(v, manager); @@ -517,5 +516,3 @@ TORRENT_TEST(no_starvation) { test_no_starvation(40000); } - - diff --git a/test/test_block_cache.cpp b/test/test_block_cache.cpp index 09a9f8b00..4c1a74112 100644 --- a/test/test_block_cache.cpp +++ b/test/test_block_cache.cpp @@ -101,7 +101,7 @@ static void nop() {} fs.set_piece_length(0x8000); \ fs.set_num_pieces(5); \ test_storage_impl* st = new test_storage_impl; \ - boost::shared_ptr pm(boost::make_shared(st, boost::shared_ptr(new int), &fs)); \ + std::shared_ptr pm = std::make_shared(st, boost::shared_ptr(new int), &fs); \ error_code ec; \ bc.set_settings(sett, ec); \ st->m_settings = &sett; \ diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 7061fd71f..7174dc277 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -463,7 +463,7 @@ void test_check_files(std::string const& test_path p.mode = storage_mode; boost::shared_ptr dummy; - boost::shared_ptr pm = boost::make_shared(new default_storage(p), dummy, &fs); + std::shared_ptr pm = std::make_shared(new default_storage(p), dummy, &fs); std::mutex lock; bool done = false; @@ -1377,4 +1377,3 @@ TORRENT_TEST(dont_move_intermingled_files) TEST_CHECK(!exists(combine_path(test_path, combine_path("temp_storage" , combine_path("_folder3", "alien_folder1"))))); } - diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index 91b7202e5..5029c26de 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -161,8 +161,8 @@ void run_upnp_test(char const* root_filename, char const* router_model, char con std::string user_agent = "test agent"; - boost::shared_ptr upnp_handler(new upnp(std::ref(ios) - , user_agent, &callback, &log_callback, false)); + std::shared_ptr upnp_handler = std::make_shared(std::ref(ios) + , user_agent, &callback, &log_callback, false); upnp_handler->start(); upnp_handler->discover_device();