From 6e891a0211aed09451c31f14ca64244e1ecae893 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 31 Aug 2016 12:45:45 -0400 Subject: [PATCH] refactor to use std::shared_ptr with http_connection (#1049) --- include/libtorrent/aux_/session_impl.hpp | 32 +++++------ include/libtorrent/http_connection.hpp | 4 +- .../libtorrent/http_tracker_connection.hpp | 2 +- include/libtorrent/peer_connection.hpp | 6 +- include/libtorrent/socket_type.hpp | 37 ++++++------- include/libtorrent/socks5_stream.hpp | 2 +- include/libtorrent/ssl_stream.hpp | 11 ++-- include/libtorrent/upnp.hpp | 2 +- include/libtorrent/utp_socket_manager.hpp | 3 +- simulation/test_http_connection.cpp | 4 +- src/http_connection.cpp | 14 ++--- src/session_impl.cpp | 55 +++++++++---------- src/socket_type.cpp | 38 ++++++------- src/torrent.cpp | 10 ++-- src/utp_socket_manager.cpp | 5 +- test/test_http_connection.cpp | 5 +- 16 files changed, 109 insertions(+), 121 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 256c0d6a0..f3475864e 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -165,8 +165,8 @@ namespace libtorrent // pointers may be nullptr! // These must be shared_ptr to avoid a dangling reference if an // incoming packet is in the event queue when the socket is erased - boost::shared_ptr sock; - boost::shared_ptr udp_sock; + std::shared_ptr sock; + std::shared_ptr udp_sock; }; namespace aux @@ -269,15 +269,15 @@ namespace libtorrent tcp::endpoint get_ipv6_interface() const override; tcp::endpoint get_ipv4_interface() const override; - void async_accept(boost::shared_ptr const& listener, bool ssl); - void on_accept_connection(boost::shared_ptr const& s - , boost::weak_ptr listener, error_code const& e, bool ssl); - void on_socks_listen(boost::shared_ptr const& s + void async_accept(std::shared_ptr const& listener, bool ssl); + void on_accept_connection(std::shared_ptr const& s + , std::weak_ptr listener, error_code const& e, bool ssl); + void on_socks_listen(std::shared_ptr const& s , error_code const& e); - void on_socks_accept(boost::shared_ptr const& s + void on_socks_accept(std::shared_ptr const& s , error_code const& e); - void incoming_connection(boost::shared_ptr const& s); + void incoming_connection(std::shared_ptr const& s); std::weak_ptr find_torrent(sha1_hash const& info_hash) const override; #ifndef TORRENT_NO_DEPRECATE @@ -554,7 +554,7 @@ namespace libtorrent void on_i2p_open(error_code const& ec); void open_new_incoming_i2p_connection(); - void on_i2p_accept(boost::shared_ptr const& s + void on_i2p_accept(std::shared_ptr const& s , error_code const& e); #endif @@ -842,7 +842,7 @@ namespace libtorrent // are performing SSL handshake. When we shut down // the session, all of these are disconnected, otherwise // they would linger and stall or hang session shutdown - std::set > m_incoming_sockets; + std::set> m_incoming_sockets; // maps IP ranges to bitfields representing peer class IDs // to assign peers matching a specific IP range based on its @@ -892,18 +892,18 @@ namespace libtorrent #if TORRENT_USE_I2P i2p_connection m_i2p_conn; - boost::shared_ptr m_i2p_listen_socket; + std::shared_ptr m_i2p_listen_socket; #endif #ifdef TORRENT_USE_OPENSSL ssl::context* ssl_ctx() override { return &m_ssl_ctx; } - void on_incoming_utp_ssl(boost::shared_ptr const& s); - void ssl_handshake(error_code const& ec, boost::shared_ptr s); + void on_incoming_utp_ssl(std::shared_ptr const& s); + void ssl_handshake(error_code const& ec, std::shared_ptr s); #endif // when as a socks proxy is used for peers, also // listen for incoming connections on a socks connection - boost::shared_ptr m_socks_listen_socket; + std::shared_ptr m_socks_listen_socket; std::uint16_t m_socks_listen_port = 0; // round-robin index into m_outgoing_interfaces @@ -1051,9 +1051,9 @@ namespace libtorrent , error_code& ec , int flags); - void on_udp_writeable(boost::weak_ptr s, error_code const& ec); + void on_udp_writeable(std::weak_ptr s, error_code const& ec); - void on_udp_packet(boost::weak_ptr const& s + void on_udp_packet(std::weak_ptr const& s , bool ssl, error_code const& ec); libtorrent::utp_socket_manager m_utp_socket_manager; diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index ea4bdcfb4..4773b7f1c 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -75,7 +75,7 @@ typedef std::function&)> http_ // when bottled, the last two arguments to the handler // will always be 0 struct TORRENT_EXTRA_EXPORT http_connection - : boost::enable_shared_from_this + : std::enable_shared_from_this , boost::noncopyable { http_connection(io_service& ios @@ -138,7 +138,7 @@ private: void on_connect(error_code const& e); void on_write(error_code const& e); void on_read(error_code const& e, std::size_t bytes_transferred); - static void on_timeout(boost::weak_ptr p + static void on_timeout(std::weak_ptr p , error_code const& e); void on_assign_bandwidth(error_code const& e); diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp index 56c6cbf9a..6096cd632 100644 --- a/include/libtorrent/http_tracker_connection.hpp +++ b/include/libtorrent/http_tracker_connection.hpp @@ -91,7 +91,7 @@ namespace libtorrent virtual void on_timeout(error_code const&) {} tracker_manager& m_man; - boost::shared_ptr m_tracker_connection; + std::shared_ptr m_tracker_connection; address m_tracker_ip; #if TORRENT_USE_I2P i2p_connection* m_i2p_conn; diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index d47b0a9f7..483f31569 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -164,7 +164,7 @@ namespace libtorrent disk_interface* disk_thread; io_service* ios; std::weak_ptr tor; - boost::shared_ptr s; + std::shared_ptr s; tcp::endpoint endp; torrent_peer* peerinfo; }; @@ -467,7 +467,7 @@ namespace libtorrent void timeout_requests(); - boost::shared_ptr get_socket() const { return m_socket; } + std::shared_ptr get_socket() const { return m_socket; } tcp::endpoint const& remote() const { return m_remote; } tcp::endpoint local_endpoint() const { return m_local; } @@ -798,7 +798,7 @@ namespace libtorrent int wanted_transfer(int channel); int request_bandwidth(int channel, int bytes = 0); - boost::shared_ptr m_socket; + std::shared_ptr m_socket; // the queue of blocks we have requested // from this peer diff --git a/include/libtorrent/socket_type.hpp b/include/libtorrent/socket_type.hpp index 5657650c0..b6ece5624 100644 --- a/include/libtorrent/socket_type.hpp +++ b/include/libtorrent/socket_type.hpp @@ -74,24 +74,24 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_USE_OPENSSL #define TORRENT_SOCKTYPE_SSL_FORWARD(x) \ - case socket_type_int_impl >::value: \ - get >()->x; break; \ - case socket_type_int_impl >::value: \ - get >()->x; break; \ - case socket_type_int_impl >::value: \ - get >()->x; break; \ - case socket_type_int_impl >::value: \ - get >()->x; break; + case socket_type_int_impl>::value: \ + get>()->x; break; \ + case socket_type_int_impl>::value: \ + get>()->x; break; \ + case socket_type_int_impl>::value: \ + get>()->x; break; \ + case socket_type_int_impl>::value: \ + get>()->x; break; #define TORRENT_SOCKTYPE_SSL_FORWARD_RET(x, def) \ - case socket_type_int_impl >::value: \ + case socket_type_int_impl>::value: \ return get >()->x; \ - case socket_type_int_impl >::value: \ + case socket_type_int_impl>::value: \ return get >()->x; \ - case socket_type_int_impl >::value: \ + case socket_type_int_impl>::value: \ return get >()->x; \ - case socket_type_int_impl >::value: \ - return get >()->x; + case socket_type_int_impl>::value: \ + return get>()->x; #else @@ -161,19 +161,19 @@ namespace libtorrent #ifdef TORRENT_USE_OPENSSL template <> - struct socket_type_int_impl > + struct socket_type_int_impl> { enum { value = 6 }; }; template <> - struct socket_type_int_impl > + struct socket_type_int_impl> { enum { value = 7 }; }; template <> - struct socket_type_int_impl > + struct socket_type_int_impl> { enum { value = 8 }; }; template <> - struct socket_type_int_impl > + struct socket_type_int_impl> { enum { value = 9 }; }; #endif @@ -333,8 +333,7 @@ namespace libtorrent void setup_ssl_hostname(socket_type& s, std::string const& hostname, error_code& ec); // properly shuts down SSL sockets. holder keeps s alive - void async_shutdown(socket_type& s, boost::shared_ptr holder); + void async_shutdown(socket_type& s, std::shared_ptr holder); } #endif - diff --git a/include/libtorrent/socks5_stream.hpp b/include/libtorrent/socks5_stream.hpp index 8b2a3c70b..489afab21 100644 --- a/include/libtorrent/socks5_stream.hpp +++ b/include/libtorrent/socks5_stream.hpp @@ -111,7 +111,7 @@ public: TORRENT_ASSERT(m_command == socks5_bind); // to avoid unnecessary copying of the handler, - // store it in a shaed_ptr + // store it in a shared_ptr error_code e; #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("socks5_stream::connect1"); diff --git a/include/libtorrent/ssl_stream.hpp b/include/libtorrent/ssl_stream.hpp index 6fd4adf44..ba2e40920 100644 --- a/include/libtorrent/ssl_stream.hpp +++ b/include/libtorrent/ssl_stream.hpp @@ -96,9 +96,7 @@ public: void set_verify_callback(T const& fun, error_code& ec) { m_sock.set_verify_callback(fun, ec); } -#if BOOST_VERSION >= 104700 SSL* native_handle() { return m_sock.native_handle(); } -#endif typedef std::function handler_type; @@ -111,7 +109,7 @@ public: // to avoid unnecessary copying of the handler, // store it in a shared_ptr - boost::shared_ptr h(new handler_type(handler)); + std::shared_ptr h(new handler_type(handler)); using std::placeholders::_1; m_sock.next_layer().async_connect(endpoint @@ -122,7 +120,7 @@ public: void async_accept_handshake(Handler const& handler) { // this is used for accepting SSL connections - boost::shared_ptr h(new handler_type(handler)); + std::shared_ptr h(new handler_type(handler)); using std::placeholders::_1; m_sock.async_handshake(ssl::stream_base::server , std::bind(&ssl_stream::handshake, this, _1, h)); @@ -312,7 +310,7 @@ public: private: - void connected(error_code const& e, boost::shared_ptr h) + void connected(error_code const& e, std::shared_ptr h) { if (e) { @@ -325,7 +323,7 @@ private: , std::bind(&ssl_stream::handshake, this, _1, h)); } - void handshake(error_code const& e, boost::shared_ptr h) + void handshake(error_code const& e, std::shared_ptr h) { (*h)(e); } @@ -338,4 +336,3 @@ private: #endif // TORRENT_USE_OPENSSL #endif - diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index b6bfb5558..f7c26b6f5 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -333,7 +333,7 @@ private: // this is only relevant if ignore_non_routers is set. bool non_router; - mutable boost::shared_ptr upnp_connection; + mutable std::shared_ptr upnp_connection; #if TORRENT_USE_ASSERTS int magic; diff --git a/include/libtorrent/utp_socket_manager.hpp b/include/libtorrent/utp_socket_manager.hpp index b301bda11..7b103d203 100644 --- a/include/libtorrent/utp_socket_manager.hpp +++ b/include/libtorrent/utp_socket_manager.hpp @@ -54,7 +54,7 @@ namespace libtorrent , span , error_code&, int)> send_fun_t; - typedef std::function const&)> + typedef std::function const&)> incoming_utp_callback_t; utp_socket_manager(send_fun_t const& send_fun @@ -186,4 +186,3 @@ namespace libtorrent } #endif - diff --git a/simulation/test_http_connection.cpp b/simulation/test_http_connection.cpp index c4da8d297..0888a84b6 100644 --- a/simulation/test_http_connection.cpp +++ b/simulation/test_http_connection.cpp @@ -110,7 +110,7 @@ std::string chunk_string(std::string s) return ret; } -boost::shared_ptr test_request(io_service& ios +std::shared_ptr test_request(io_service& ios , resolver& res , std::string const& url , char const* expected_data @@ -124,7 +124,7 @@ boost::shared_ptr test_request(io_service& ios { std::fprintf(stderr, " ===== TESTING: %s =====\n", url.c_str()); - auto h = boost::make_shared(ios + auto h = std::make_shared(ios , res , [=](error_code const& ec, http_parser const& parser , char const* data, const int size, http_connection&) diff --git a/src/http_connection.cpp b/src/http_connection.cpp index b6c499439..69c95d80c 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -137,7 +137,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri // keep ourselves alive even if the callback function // deletes this object - boost::shared_ptr me(shared_from_this()); + std::shared_ptr me(shared_from_this()); if (ec) { @@ -240,7 +240,7 @@ void http_connection::start(std::string const& hostname, int port // keep ourselves alive even if the callback function // deletes this object - boost::shared_ptr me(shared_from_this()); + std::shared_ptr me(shared_from_this()); m_completion_timeout = timeout; m_read_timeout = seconds(5); @@ -250,7 +250,7 @@ void http_connection::start(std::string const& hostname, int port m_read_timeout, m_completion_timeout), ec); ADD_OUTSTANDING_ASYNC("http_connection::on_timeout"); m_timer.async_wait(std::bind(&http_connection::on_timeout - , boost::weak_ptr(me), _1)); + , std::weak_ptr(me), _1)); m_called = false; m_parser.reset(); m_recvbuffer.clear(); @@ -411,11 +411,11 @@ void http_connection::start(std::string const& hostname, int port } } -void http_connection::on_timeout(boost::weak_ptr p +void http_connection::on_timeout(std::weak_ptr p , error_code const& e) { COMPLETE_ASYNC("http_connection::on_timeout"); - boost::shared_ptr c = p.lock(); + std::shared_ptr c = p.lock(); if (!c) return; if (e == boost::asio::error::operation_aborted) return; @@ -546,7 +546,7 @@ void http_connection::connect() { TORRENT_ASSERT(m_next_ep < m_endpoints.size()); - boost::shared_ptr me(shared_from_this()); + std::shared_ptr me(shared_from_this()); if (m_proxy.proxy_hostnames && (m_proxy.type == settings_pack::socks5 @@ -713,7 +713,7 @@ void http_connection::on_read(error_code const& e // keep ourselves alive even if the callback function // deletes this object - boost::shared_ptr me(shared_from_this()); + std::shared_ptr me(shared_from_this()); // when using the asio SSL wrapper, it seems like // we get the shut_down error instead of EOF diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 2f95a686e..fe7c9cbb4 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -817,10 +817,9 @@ namespace aux { #endif m_lsd_announce_timer.cancel(ec); - for (std::set >::iterator i = m_incoming_sockets.begin() - , end(m_incoming_sockets.end()); i != end; ++i) + for (auto const& s : m_incoming_sockets) { - (*i)->close(ec); + s->close(ec); TORRENT_ASSERT(!ec); } m_incoming_sockets.clear(); @@ -1494,7 +1493,7 @@ namespace aux { // separate function. At least most of it if (!m_settings.get_bool(settings_pack::force_proxy)) { - ret.sock = boost::make_shared(std::ref(m_io_service)); + ret.sock = std::make_shared(m_io_service); ret.sock->open(bind_ep.protocol(), ec); last_op = listen_failed_alert::open; if (ec) @@ -1677,7 +1676,7 @@ namespace aux { } } // force-proxy mode - ret.udp_sock = boost::make_shared(std::ref(m_io_service)); + ret.udp_sock = std::make_shared(m_io_service); #if TORRENT_HAS_BINDTODEVICE if (!device.empty()) { @@ -1736,7 +1735,7 @@ namespace aux { // TODO: 2 use a handler allocator here ADD_OUTSTANDING_ASYNC("session_impl::on_udp_packet"); ret.udp_sock->async_read(std::bind(&session_impl::on_udp_packet - , this, boost::weak_ptr(ret.udp_sock), ret.ssl, _1)); + , this, std::weak_ptr(ret.udp_sock), ret.ssl, _1)); #ifndef TORRENT_DISABLE_LOGGING session_log(" listening on: %s TCP port: %d UDP port: %d" @@ -1973,7 +1972,7 @@ namespace aux { if (m_socks_listen_socket) return; - m_socks_listen_socket = boost::make_shared(std::ref(m_io_service)); + m_socks_listen_socket = std::make_shared(m_io_service); bool const ret = instantiate_connection(m_io_service, proxy() , *m_socks_listen_socket, nullptr, nullptr, false, false); TORRENT_ASSERT_VAL(ret, ret); @@ -1989,7 +1988,7 @@ namespace aux { , m_socks_listen_socket, _1)); } - void session_impl::on_socks_listen(boost::shared_ptr const& sock + void session_impl::on_socks_listen(std::shared_ptr const& sock , error_code const& e) { #if defined TORRENT_ASIO_DEBUGGING @@ -2026,7 +2025,7 @@ namespace aux { , m_socks_listen_socket, _1)); } - void session_impl::on_socks_accept(boost::shared_ptr const& s + void session_impl::on_socks_accept(std::shared_ptr const& s , error_code const& e) { COMPLETE_ASYNC("session_impl::on_socks_accept"); @@ -2100,7 +2099,7 @@ namespace aux { if (m_i2p_listen_socket) return; - m_i2p_listen_socket = boost::shared_ptr(new socket_type(m_io_service)); + m_i2p_listen_socket = std::shared_ptr(new socket_type(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); @@ -2115,7 +2114,7 @@ namespace aux { , std::bind(&session_impl::on_i2p_accept, this, m_i2p_listen_socket, _1)); } - void session_impl::on_i2p_accept(boost::shared_ptr const& s + void session_impl::on_i2p_accept(std::shared_ptr const& s , error_code const& e) { COMPLETE_ASYNC("session_impl::on_i2p_accept"); @@ -2163,7 +2162,7 @@ namespace aux { i->udp_write_blocked = true; ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable"); i->udp_sock->async_write(std::bind(&session_impl::on_udp_writeable - , this, boost::weak_ptr(i->udp_sock), _1)); + , this, std::weak_ptr(i->udp_sock), _1)); } return; } @@ -2196,19 +2195,19 @@ namespace aux { i->udp_write_blocked = true; ADD_OUTSTANDING_ASYNC("session_impl::on_udp_writeable"); i->udp_sock->async_write(std::bind(&session_impl::on_udp_writeable - , this, boost::weak_ptr(i->udp_sock), _1)); + , this, std::weak_ptr(i->udp_sock), _1)); } return; } ec = boost::asio::error::operation_not_supported; } - void session_impl::on_udp_writeable(boost::weak_ptr s, error_code const& ec) + void session_impl::on_udp_writeable(std::weak_ptr s, error_code const& ec) { COMPLETE_ASYNC("session_impl::on_udp_writeable"); if (ec) return; - boost::shared_ptr sock = s.lock(); + std::shared_ptr sock = s.lock(); if (!sock) return; std::list::iterator i = std::find_if( @@ -2230,13 +2229,13 @@ namespace aux { } - void session_impl::on_udp_packet(boost::weak_ptr const& socket + void session_impl::on_udp_packet(std::weak_ptr const& socket , bool const ssl, error_code const& ec) { COMPLETE_ASYNC("session_impl::on_udp_packet"); if (ec) { - boost::shared_ptr s = socket.lock(); + std::shared_ptr s = socket.lock(); udp::endpoint ep; error_code best_effort; if (s) ep = s->local_endpoint(best_effort); @@ -2258,7 +2257,7 @@ namespace aux { m_stats_counters.inc_stats_counter(counters::on_udp_counter); - boost::shared_ptr s = socket.lock(); + std::shared_ptr s = socket.lock(); if (!s) return; struct utp_socket_manager& mgr = @@ -2372,10 +2371,10 @@ namespace aux { , this, socket, ssl, _1)); } - void session_impl::async_accept(boost::shared_ptr const& listener, bool ssl) + void session_impl::async_accept(std::shared_ptr const& listener, bool ssl) { TORRENT_ASSERT(!m_abort); - shared_ptr c(new socket_type(m_io_service)); + std::shared_ptr c = std::make_shared(m_io_service); tcp::socket* str = nullptr; #ifdef TORRENT_USE_OPENSSL @@ -2403,17 +2402,17 @@ namespace aux { listener->async_accept(*str , std::bind(&session_impl::on_accept_connection, this, c - , boost::weak_ptr(listener), _1, ssl)); + , std::weak_ptr(listener), _1, ssl)); } - void session_impl::on_accept_connection(shared_ptr const& s - , weak_ptr listen_socket, error_code const& e + void session_impl::on_accept_connection(std::shared_ptr const& s + , std::weak_ptr listen_socket, error_code const& e , bool const ssl) { COMPLETE_ASYNC("session_impl::on_accept_connection"); m_stats_counters.inc_stats_counter(counters::on_accept_counter); TORRENT_ASSERT(is_single_thread()); - boost::shared_ptr listener = listen_socket.lock(); + std::shared_ptr listener = listen_socket.lock(); if (!listener) return; if (e == boost::asio::error::operation_aborted) return; @@ -2505,14 +2504,14 @@ namespace aux { #ifdef TORRENT_USE_OPENSSL - void session_impl::on_incoming_utp_ssl(boost::shared_ptr const& s) + void session_impl::on_incoming_utp_ssl(std::shared_ptr const& s) { TORRENT_ASSERT(is_ssl(*s)); // for SSL connections, incoming_connection() is called // after the handshake is done ADD_OUTSTANDING_ASYNC("session_impl::ssl_handshake"); - s->get >()->async_accept_handshake( + s->get>()->async_accept_handshake( std::bind(&session_impl::ssl_handshake, this, _1, s)); m_incoming_sockets.insert(s); } @@ -2523,7 +2522,7 @@ namespace aux { // -CAfile .pem -debug -connect 127.0.0.1:4433 -tls1 // -servername - void session_impl::ssl_handshake(error_code const& ec, boost::shared_ptr s) + void session_impl::ssl_handshake(error_code const& ec, std::shared_ptr s) { COMPLETE_ASYNC("session_impl::ssl_handshake"); TORRENT_ASSERT(is_ssl(*s)); @@ -2554,7 +2553,7 @@ namespace aux { #endif // TORRENT_USE_OPENSSL - void session_impl::incoming_connection(boost::shared_ptr const& s) + void session_impl::incoming_connection(std::shared_ptr const& s) { TORRENT_ASSERT(is_single_thread()); diff --git a/src/socket_type.cpp b/src/socket_type.cpp index ca556961c..ea942b1b7 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -36,10 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #ifdef TORRENT_USE_OPENSSL #include - -#if BOOST_VERSION >= 104700 #include -#endif #endif @@ -137,7 +134,7 @@ namespace libtorrent #ifdef TORRENT_USE_OPENSSL namespace { - void on_close_socket(socket_type* s, boost::shared_ptr) + void on_close_socket(socket_type* s, std::shared_ptr) { COMPLETE_ASYNC("on_close_socket"); error_code ec; @@ -149,7 +146,7 @@ namespace libtorrent // the second argument is a shared pointer to an object that // will keep the socket (s) alive for the duration of the async operation - void async_shutdown(socket_type& s, boost::shared_ptr holder) + void async_shutdown(socket_type& s, std::shared_ptr holder) { error_code e; @@ -161,9 +158,9 @@ namespace libtorrent #define MAYBE_ASIO_DEBUGGING #endif -#define CASE(t) case socket_type_int_impl >::value: \ +#define CASE(t) case socket_type_int_impl>::value: \ MAYBE_ASIO_DEBUGGING \ - s.get >()->async_shutdown(std::bind(&on_close_socket, &s, holder)); \ + s.get>()->async_shutdown(std::bind(&on_close_socket, &s, holder)); \ break; switch (s.type()) @@ -205,17 +202,17 @@ namespace libtorrent break; #endif #ifdef TORRENT_USE_OPENSSL - case socket_type_int_impl >::value: - get >()->~ssl_stream(); + case socket_type_int_impl>::value: + get>()->~ssl_stream(); break; - case socket_type_int_impl >::value: - get >()->~ssl_stream(); + case socket_type_int_impl>::value: + get>()->~ssl_stream(); break; - case socket_type_int_impl >::value: - get >()->~ssl_stream(); + case socket_type_int_impl>::value: + get>()->~ssl_stream(); break; - case socket_type_int_impl >::value: - get >()->~ssl_stream(); + case socket_type_int_impl>::value: + get>()->~ssl_stream(); break; #endif default: TORRENT_ASSERT_FAIL(); @@ -251,22 +248,22 @@ namespace libtorrent break; #endif #ifdef TORRENT_USE_OPENSSL - case socket_type_int_impl >::value: + case socket_type_int_impl>::value: TORRENT_ASSERT(userdata); new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; - case socket_type_int_impl >::value: + case socket_type_int_impl>::value: TORRENT_ASSERT(userdata); new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; - case socket_type_int_impl >::value: + case socket_type_int_impl>::value: TORRENT_ASSERT(userdata); new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); break; - case socket_type_int_impl >::value: + case socket_type_int_impl>::value: TORRENT_ASSERT(userdata); new (reinterpret_cast*>(&m_data)) ssl_stream(m_io_service , *static_cast(userdata)); @@ -348,7 +345,7 @@ namespace libtorrent case socket_type_int_impl::value: return get()->get_close_reason(); #ifdef TORRENT_USE_OPENSSL - case socket_type_int_impl >::value: + case socket_type_int_impl>::value: return get >()->lowest_layer().get_close_reason(); #endif default: return 0; @@ -393,4 +390,3 @@ namespace libtorrent #endif } - diff --git a/src/torrent.cpp b/src/torrent.cpp index d589d7134..12ba3c954 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -737,7 +737,7 @@ namespace libtorrent { TORRENT_ASSERT(!m_url.empty()); TORRENT_ASSERT(!m_torrent_file->is_valid()); - boost::shared_ptr conn( + std::shared_ptr conn( new http_connection(m_ses.get_io_service() , m_ses.get_resolver() , std::bind(&torrent::on_torrent_download, shared_from_this() @@ -6111,8 +6111,8 @@ namespace libtorrent if (is_paused()) return; if (m_ses.is_aborted()) return; - boost::shared_ptr s - = boost::make_shared(std::ref(m_ses.get_io_service())); + std::shared_ptr s + = std::make_shared(m_ses.get_io_service()); if (!s) return; void* userdata = nullptr; @@ -6787,7 +6787,7 @@ namespace libtorrent || !m_ip_filter || (m_ip_filter->access(peerinfo->address()) & ip_filter::blocked) == 0); - boost::shared_ptr s(new socket_type(m_ses.get_io_service())); + std::shared_ptr s = std::make_shared(m_ses.get_io_service()); #if TORRENT_USE_I2P bool i2p = peerinfo->is_i2p_addr; @@ -7050,7 +7050,7 @@ namespace libtorrent if (is_ssl_torrent()) { // if this is an SSL torrent, don't allow non SSL peers on it - boost::shared_ptr s = p->get_socket(); + std::shared_ptr s = p->get_socket(); // #define SSL(t) socket_type_int_impl>::value: \ diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index c22ec3b19..ebfc14bae 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -215,7 +215,7 @@ namespace libtorrent // UTP_LOGV("not found, new connection id:%d\n", m_new_connection); - boost::shared_ptr c(new (std::nothrow) socket_type(m_ios)); + std::shared_ptr c(new (std::nothrow) socket_type(m_ios)); if (!c) return false; TORRENT_ASSERT(m_new_connection == -1); @@ -228,7 +228,7 @@ namespace libtorrent utp_stream* str = nullptr; #ifdef TORRENT_USE_OPENSSL if (is_ssl(*c)) - str = &c->get >()->next_layer(); + str = &c->get>()->next_layer(); else #endif str = c->get(); @@ -346,4 +346,3 @@ namespace libtorrent return impl; } } - diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index 452a24c73..1592f5864 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -119,8 +119,8 @@ void run_test(std::string const& url, int size, int status, int connected << " connected: " << connected << " error: " << (ec?ec->message():"no error") << std::endl; - boost::shared_ptr h(new http_connection(ios - , res, &::http_handler, true, 1024*1024, &::http_connect_handler)); + std::shared_ptr h = std::make_shared(ios + , res, &::http_handler, true, 1024*1024, &::http_connect_handler); h->get(url, seconds(1), 0, &ps, 5, "test/user-agent", address_v4::any() , 0, auth); ios.reset(); @@ -225,4 +225,3 @@ TORRENT_TEST(no_keepalive) { run_suite("http", settings_pack::none, 0); } -