From 4c7e24ea35ba1eb656784538fccd545152cb9a10 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Thu, 17 Nov 2016 14:34:49 -0500 Subject: [PATCH] more use of std::make_shared, fixing warnings of over-aligned --- .../libtorrent/aux_/allocating_handler.hpp | 1 + include/libtorrent/http_stream.hpp | 2 +- include/libtorrent/i2p_stream.hpp | 2 +- include/libtorrent/proxy_base.hpp | 6 ++++-- include/libtorrent/socks5_stream.hpp | 4 ++-- include/libtorrent/ssl_stream.hpp | 6 +++--- src/alert.cpp | 2 +- src/http_tracker_connection.cpp | 10 ++++----- src/kademlia/node.cpp | 12 +++-------- src/session_impl.cpp | 2 +- src/socks5_stream.cpp | 2 +- src/torrent.cpp | 2 +- src/upnp.cpp | 21 +++++++++---------- 13 files changed, 34 insertions(+), 38 deletions(-) diff --git a/include/libtorrent/aux_/allocating_handler.hpp b/include/libtorrent/aux_/allocating_handler.hpp index 6c6bd760d..3c221ed60 100644 --- a/include/libtorrent/aux_/allocating_handler.hpp +++ b/include/libtorrent/aux_/allocating_handler.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_ALLOCATING_HANDLER_HPP_INCLUDED #include "libtorrent/config.hpp" +#include "libtorrent/error_code.hpp" #include diff --git a/include/libtorrent/http_stream.hpp b/include/libtorrent/http_stream.hpp index aa2b1e854..f4aa0d702 100644 --- a/include/libtorrent/http_stream.hpp +++ b/include/libtorrent/http_stream.hpp @@ -90,7 +90,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); using std::placeholders::_1; using std::placeholders::_2; diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 1f7826820..e8d8feb7f 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -115,7 +115,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); using std::placeholders::_1; using std::placeholders::_2; diff --git a/include/libtorrent/proxy_base.hpp b/include/libtorrent/proxy_base.hpp index f46948043..8bd4edffe 100644 --- a/include/libtorrent/proxy_base.hpp +++ b/include/libtorrent/proxy_base.hpp @@ -41,11 +41,11 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { -class proxy_base : boost::noncopyable +class proxy_base { public: - typedef std::function handler_type; + using handler_type = std::function; typedef tcp::socket next_layer_type; typedef tcp::socket::lowest_layer_type lowest_layer_type; @@ -54,6 +54,8 @@ public: explicit proxy_base(io_service& io_service); ~proxy_base(); + proxy_base(proxy_base const&) = delete; + proxy_base& operator=(proxy_base const&) = delete; void set_proxy(std::string hostname, int port) { diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index aca262688..44f1698b0 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -134,7 +134,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("socks5_stream::name_lookup"); @@ -207,7 +207,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); using std::placeholders::_1; using std::placeholders::_2; diff --git a/include/libtorrent/ssl_stream.hpp b/include/libtorrent/ssl_stream.hpp index 9bf54369c..aff321a19 100644 --- a/include/libtorrent/ssl_stream.hpp +++ b/include/libtorrent/ssl_stream.hpp @@ -90,7 +90,7 @@ public: SSL* native_handle() { return m_sock.native_handle(); } - typedef std::function handler_type; + using handler_type = std::function; template void async_connect(endpoint_type const& endpoint, Handler const& handler) @@ -101,7 +101,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); using std::placeholders::_1; m_sock.next_layer().async_connect(endpoint @@ -112,7 +112,7 @@ public: void async_accept_handshake(Handler const& handler) { // this is used for accepting SSL connections - std::shared_ptr h(new handler_type(handler)); + auto h = std::make_shared(handler); using std::placeholders::_1; m_sock.async_handshake(ssl::stream_base::server , std::bind(&ssl_stream::handshake, this, _1, h)); diff --git a/src/alert.cpp b/src/alert.cpp index 4ccc771cd..8bba7f9d0 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -717,7 +717,7 @@ namespace libtorrent { std::string torrent_delete_failed_alert::message() const { return torrent_alert::message() + " torrent deletion failed: " - +convert_from_native(error.message()); + + convert_from_native(error.message()); } save_resume_data_alert::save_resume_data_alert(aux::stack_allocator& alloc diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 106e29aa6..8f36a78bc 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -195,7 +195,7 @@ namespace libtorrent } #endif - m_tracker_connection.reset(new http_connection(get_io_service(), m_man.host_resolver() + m_tracker_connection = std::make_shared(get_io_service(), m_man.host_resolver() , std::bind(&http_tracker_connection::on_response, shared_from_this(), _1, _2, _3, _4) , true, settings.get_int(settings_pack::max_http_recv_buffer_size) , std::bind(&http_tracker_connection::on_connect, shared_from_this(), _1) @@ -203,11 +203,11 @@ namespace libtorrent #ifdef TORRENT_USE_OPENSSL , tracker_req().ssl_ctx #endif - )); + ); - int timeout = tracker_req().event==tracker_request::stopped - ?settings.get_int(settings_pack::stop_tracker_timeout) - :settings.get_int(settings_pack::tracker_completion_timeout); + int const timeout = tracker_req().event==tracker_request::stopped + ? settings.get_int(settings_pack::stop_tracker_timeout) + : settings.get_int(settings_pack::tracker_completion_timeout); // when sending stopped requests, prefer the cached DNS entry // to avoid being blocked for slow or failing responses. Chances diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 15c890785..c5fb4942e 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -429,15 +429,9 @@ void node::get_peers(sha1_hash const& info_hash // search for nodes with ids close to id or with peers // for info-hash id. then send announce_peer to them. - std::shared_ptr ta; - if (m_settings.privacy_lookups) - { - ta.reset(new dht::obfuscated_get_peers(*this, info_hash, dcallback, ncallback, noseeds)); - } - else - { - ta.reset(new dht::get_peers(*this, info_hash, dcallback, ncallback, noseeds)); - } + auto ta = m_settings.privacy_lookups + ? std::make_shared(*this, info_hash, dcallback, ncallback, noseeds) + : std::make_shared(*this, info_hash, dcallback, ncallback, noseeds); ta->start(); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f5c7fd623..94177a42c 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2061,7 +2061,7 @@ namespace aux { if (m_i2p_listen_socket) return; - m_i2p_listen_socket = std::shared_ptr(new socket_type(m_io_service)); + m_i2p_listen_socket = std::make_shared(m_io_service); bool ret = instantiate_connection(m_io_service, m_i2p_conn.proxy() , *m_i2p_listen_socket, nullptr, nullptr, true, false); TORRENT_ASSERT_VAL(ret, ret); diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 44f8cae3f..007b748e7 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -143,7 +143,7 @@ namespace libtorrent if (handle_error(ec, h)) return; } - // TOOD: we could bind the socket here, since we know what the + // TODO: we could bind the socket here, since we know what the // target endpoint is of the proxy ADD_OUTSTANDING_ASYNC("socks5_stream::connected"); m_sock.async_connect(i->endpoint(), std::bind( diff --git a/src/torrent.cpp b/src/torrent.cpp index 0e34e778f..f000d53c2 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8538,7 +8538,7 @@ namespace libtorrent state_updated(); - std::shared_ptr rd(new entry); + auto rd = std::make_shared(); write_resume_data(*rd); alerts().emplace_alert(rd, get_handle()); } diff --git a/src/upnp.cpp b/src/upnp.cpp index a1de5807b..38045fe58 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -317,10 +317,10 @@ void upnp::resend_request(error_code const& ec) log("connecting to: %s", d.url.c_str()); #endif if (d.upnp_connection) d.upnp_connection->close(); - d.upnp_connection.reset(new http_connection(m_io_service + d.upnp_connection = std::make_shared(m_io_service , m_resolver , std::bind(&upnp::on_upnp_xml, self(), _1, _2 - , std::ref(d), _5))); + , std::ref(d), _5)); d.upnp_connection->get(d.url, seconds(30), 1); } TORRENT_CATCH (std::exception const& exc) @@ -665,10 +665,10 @@ void upnp::try_map_upnp(bool timer) #endif if (d.upnp_connection) d.upnp_connection->close(); - d.upnp_connection.reset(new http_connection(m_io_service + d.upnp_connection = std::make_shared(m_io_service , m_resolver , std::bind(&upnp::on_upnp_xml, self(), _1, _2 - , std::ref(d), _5))); + , std::ref(d), _5)); d.upnp_connection->get(d.url, seconds(30), 1); } TORRENT_CATCH (std::exception const& exc) @@ -811,11 +811,11 @@ void upnp::update_map(rootdevice& d, int i) } if (d.upnp_connection) d.upnp_connection->close(); - d.upnp_connection.reset(new http_connection(m_io_service + d.upnp_connection = std::make_shared(m_io_service , m_resolver , std::bind(&upnp::on_upnp_map_response, self(), _1, _2 , std::ref(d), i, _5), true, default_max_bottled_buffer_size - , std::bind(&upnp::create_port_mapping, self(), _1, std::ref(d), i))); + , std::bind(&upnp::create_port_mapping, self(), _1, std::ref(d), i)); d.upnp_connection->start(d.hostname, d.port , seconds(10), 1); @@ -823,11 +823,11 @@ void upnp::update_map(rootdevice& d, int i) else if (m.act == mapping_t::action::del) { if (d.upnp_connection) d.upnp_connection->close(); - d.upnp_connection.reset(new http_connection(m_io_service + d.upnp_connection = std::make_shared(m_io_service , m_resolver , std::bind(&upnp::on_upnp_unmap_response, self(), _1, _2 , std::ref(d), i, _5), true, default_max_bottled_buffer_size - , std::bind(&upnp::delete_port_mapping, self(), std::ref(d), i))); + , std::bind(&upnp::delete_port_mapping, self(), std::ref(d), i)); d.upnp_connection->start(d.hostname, d.port , seconds(10), 1); } @@ -1052,11 +1052,11 @@ void upnp::on_upnp_xml(error_code const& e return; } - d.upnp_connection.reset(new http_connection(m_io_service + d.upnp_connection = std::make_shared(m_io_service , m_resolver , std::bind(&upnp::on_upnp_get_ip_address_response, self(), _1, _2 , std::ref(d), _5), true, default_max_bottled_buffer_size - , std::bind(&upnp::get_ip_address, self(), std::ref(d)))); + , std::bind(&upnp::get_ip_address, self(), std::ref(d))); d.upnp_connection->start(d.hostname, d.port , seconds(10), 1); } @@ -1079,7 +1079,6 @@ void upnp::get_ip_address(rootdevice& d) char const* soap_action = "GetExternalIPAddress"; char soap[2048]; - error_code ec; std::snprintf(soap, sizeof(soap), "\n" ""