refactor to use std::shared_ptr with http_connection (#1049)

This commit is contained in:
Alden Torres 2016-08-31 12:45:45 -04:00 committed by Arvid Norberg
parent cdb15ba886
commit 6e891a0211
16 changed files with 109 additions and 121 deletions

View File

@ -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<tcp::acceptor> sock;
boost::shared_ptr<udp_socket> udp_sock;
std::shared_ptr<tcp::acceptor> sock;
std::shared_ptr<udp_socket> 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<tcp::acceptor> const& listener, bool ssl);
void on_accept_connection(boost::shared_ptr<socket_type> const& s
, boost::weak_ptr<tcp::acceptor> listener, error_code const& e, bool ssl);
void on_socks_listen(boost::shared_ptr<socket_type> const& s
void async_accept(std::shared_ptr<tcp::acceptor> const& listener, bool ssl);
void on_accept_connection(std::shared_ptr<socket_type> const& s
, std::weak_ptr<tcp::acceptor> listener, error_code const& e, bool ssl);
void on_socks_listen(std::shared_ptr<socket_type> const& s
, error_code const& e);
void on_socks_accept(boost::shared_ptr<socket_type> const& s
void on_socks_accept(std::shared_ptr<socket_type> const& s
, error_code const& e);
void incoming_connection(boost::shared_ptr<socket_type> const& s);
void incoming_connection(std::shared_ptr<socket_type> const& s);
std::weak_ptr<torrent> 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<socket_type> const& s
void on_i2p_accept(std::shared_ptr<socket_type> 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<boost::shared_ptr<socket_type> > m_incoming_sockets;
std::set<std::shared_ptr<socket_type>> 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<socket_type> m_i2p_listen_socket;
std::shared_ptr<socket_type> 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<socket_type> const& s);
void ssl_handshake(error_code const& ec, boost::shared_ptr<socket_type> s);
void on_incoming_utp_ssl(std::shared_ptr<socket_type> const& s);
void ssl_handshake(error_code const& ec, std::shared_ptr<socket_type> s);
#endif
// when as a socks proxy is used for peers, also
// listen for incoming connections on a socks connection
boost::shared_ptr<socket_type> m_socks_listen_socket;
std::shared_ptr<socket_type> 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<udp_socket> s, error_code const& ec);
void on_udp_writeable(std::weak_ptr<udp_socket> s, error_code const& ec);
void on_udp_packet(boost::weak_ptr<udp_socket> const& s
void on_udp_packet(std::weak_ptr<udp_socket> const& s
, bool ssl, error_code const& ec);
libtorrent::utp_socket_manager m_utp_socket_manager;

View File

@ -75,7 +75,7 @@ typedef std::function<void(http_connection&, std::vector<tcp::endpoint>&)> 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<http_connection>
: std::enable_shared_from_this<http_connection>
, 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<http_connection> p
static void on_timeout(std::weak_ptr<http_connection> p
, error_code const& e);
void on_assign_bandwidth(error_code const& e);

View File

@ -91,7 +91,7 @@ namespace libtorrent
virtual void on_timeout(error_code const&) {}
tracker_manager& m_man;
boost::shared_ptr<http_connection> m_tracker_connection;
std::shared_ptr<http_connection> m_tracker_connection;
address m_tracker_ip;
#if TORRENT_USE_I2P
i2p_connection* m_i2p_conn;

View File

@ -164,7 +164,7 @@ namespace libtorrent
disk_interface* disk_thread;
io_service* ios;
std::weak_ptr<torrent> tor;
boost::shared_ptr<socket_type> s;
std::shared_ptr<socket_type> s;
tcp::endpoint endp;
torrent_peer* peerinfo;
};
@ -467,7 +467,7 @@ namespace libtorrent
void timeout_requests();
boost::shared_ptr<socket_type> get_socket() const { return m_socket; }
std::shared_ptr<socket_type> 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<socket_type> m_socket;
std::shared_ptr<socket_type> m_socket;
// the queue of blocks we have requested
// from this peer

View File

@ -74,24 +74,24 @@ POSSIBILITY OF SUCH DAMAGE.
#ifdef TORRENT_USE_OPENSSL
#define TORRENT_SOCKTYPE_SSL_FORWARD(x) \
case socket_type_int_impl<ssl_stream<tcp::socket> >::value: \
get<ssl_stream<tcp::socket> >()->x; break; \
case socket_type_int_impl<ssl_stream<socks5_stream> >::value: \
get<ssl_stream<socks5_stream> >()->x; break; \
case socket_type_int_impl<ssl_stream<http_stream> >::value: \
get<ssl_stream<http_stream> >()->x; break; \
case socket_type_int_impl<ssl_stream<utp_stream> >::value: \
get<ssl_stream<utp_stream> >()->x; break;
case socket_type_int_impl<ssl_stream<tcp::socket>>::value: \
get<ssl_stream<tcp::socket>>()->x; break; \
case socket_type_int_impl<ssl_stream<socks5_stream>>::value: \
get<ssl_stream<socks5_stream>>()->x; break; \
case socket_type_int_impl<ssl_stream<http_stream>>::value: \
get<ssl_stream<http_stream>>()->x; break; \
case socket_type_int_impl<ssl_stream<utp_stream>>::value: \
get<ssl_stream<utp_stream>>()->x; break;
#define TORRENT_SOCKTYPE_SSL_FORWARD_RET(x, def) \
case socket_type_int_impl<ssl_stream<tcp::socket> >::value: \
case socket_type_int_impl<ssl_stream<tcp::socket>>::value: \
return get<ssl_stream<tcp::socket> >()->x; \
case socket_type_int_impl<ssl_stream<socks5_stream> >::value: \
case socket_type_int_impl<ssl_stream<socks5_stream>>::value: \
return get<ssl_stream<socks5_stream> >()->x; \
case socket_type_int_impl<ssl_stream<http_stream> >::value: \
case socket_type_int_impl<ssl_stream<http_stream>>::value: \
return get<ssl_stream<http_stream> >()->x; \
case socket_type_int_impl<ssl_stream<utp_stream> >::value: \
return get<ssl_stream<utp_stream> >()->x;
case socket_type_int_impl<ssl_stream<utp_stream>>::value: \
return get<ssl_stream<utp_stream>>()->x;
#else
@ -161,19 +161,19 @@ namespace libtorrent
#ifdef TORRENT_USE_OPENSSL
template <>
struct socket_type_int_impl<ssl_stream<tcp::socket> >
struct socket_type_int_impl<ssl_stream<tcp::socket>>
{ enum { value = 6 }; };
template <>
struct socket_type_int_impl<ssl_stream<socks5_stream> >
struct socket_type_int_impl<ssl_stream<socks5_stream>>
{ enum { value = 7 }; };
template <>
struct socket_type_int_impl<ssl_stream<http_stream> >
struct socket_type_int_impl<ssl_stream<http_stream>>
{ enum { value = 8 }; };
template <>
struct socket_type_int_impl<ssl_stream<utp_stream> >
struct socket_type_int_impl<ssl_stream<utp_stream>>
{ 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<void> holder);
void async_shutdown(socket_type& s, std::shared_ptr<void> holder);
}
#endif

View File

@ -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");

View File

@ -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<void(error_code const&)> handler_type;
@ -111,7 +109,7 @@ public:
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
boost::shared_ptr<handler_type> h(new handler_type(handler));
std::shared_ptr<handler_type> 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<handler_type> h(new handler_type(handler));
std::shared_ptr<handler_type> 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<handler_type> h)
void connected(error_code const& e, std::shared_ptr<handler_type> 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<handler_type> h)
void handshake(error_code const& e, std::shared_ptr<handler_type> h)
{
(*h)(e);
}
@ -338,4 +336,3 @@ private:
#endif // TORRENT_USE_OPENSSL
#endif

View File

@ -333,7 +333,7 @@ private:
// this is only relevant if ignore_non_routers is set.
bool non_router;
mutable boost::shared_ptr<http_connection> upnp_connection;
mutable std::shared_ptr<http_connection> upnp_connection;
#if TORRENT_USE_ASSERTS
int magic;

View File

@ -54,7 +54,7 @@ namespace libtorrent
, span<char const>
, error_code&, int)> send_fun_t;
typedef std::function<void(boost::shared_ptr<socket_type> const&)>
typedef std::function<void(std::shared_ptr<socket_type> const&)>
incoming_utp_callback_t;
utp_socket_manager(send_fun_t const& send_fun
@ -186,4 +186,3 @@ namespace libtorrent
}
#endif

View File

@ -110,7 +110,7 @@ std::string chunk_string(std::string s)
return ret;
}
boost::shared_ptr<http_connection> test_request(io_service& ios
std::shared_ptr<http_connection> test_request(io_service& ios
, resolver& res
, std::string const& url
, char const* expected_data
@ -124,7 +124,7 @@ boost::shared_ptr<http_connection> test_request(io_service& ios
{
std::fprintf(stderr, " ===== TESTING: %s =====\n", url.c_str());
auto h = boost::make_shared<http_connection>(ios
auto h = std::make_shared<http_connection>(ios
, res
, [=](error_code const& ec, http_parser const& parser
, char const* data, const int size, http_connection&)

View File

@ -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<http_connection> me(shared_from_this());
std::shared_ptr<http_connection> 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<http_connection> me(shared_from_this());
std::shared_ptr<http_connection> 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<http_connection>(me), _1));
, std::weak_ptr<http_connection>(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<http_connection> p
void http_connection::on_timeout(std::weak_ptr<http_connection> p
, error_code const& e)
{
COMPLETE_ASYNC("http_connection::on_timeout");
boost::shared_ptr<http_connection> c = p.lock();
std::shared_ptr<http_connection> 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<http_connection> me(shared_from_this());
std::shared_ptr<http_connection> 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<http_connection> me(shared_from_this());
std::shared_ptr<http_connection> me(shared_from_this());
// when using the asio SSL wrapper, it seems like
// we get the shut_down error instead of EOF

View File

@ -817,10 +817,9 @@ namespace aux {
#endif
m_lsd_announce_timer.cancel(ec);
for (std::set<boost::shared_ptr<socket_type> >::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<tcp::acceptor>(std::ref(m_io_service));
ret.sock = std::make_shared<tcp::acceptor>(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<udp_socket>(std::ref(m_io_service));
ret.udp_sock = std::make_shared<udp_socket>(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<udp_socket>(ret.udp_sock), ret.ssl, _1));
, this, std::weak_ptr<udp_socket>(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<socket_type>(std::ref(m_io_service));
m_socks_listen_socket = std::make_shared<socket_type>(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<socket_type> const& sock
void session_impl::on_socks_listen(std::shared_ptr<socket_type> 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<socket_type> const& s
void session_impl::on_socks_accept(std::shared_ptr<socket_type> 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<socket_type>(new socket_type(m_io_service));
m_i2p_listen_socket = std::shared_ptr<socket_type>(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<socket_type> const& s
void session_impl::on_i2p_accept(std::shared_ptr<socket_type> 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<udp_socket>(i->udp_sock), _1));
, this, std::weak_ptr<udp_socket>(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<udp_socket>(i->udp_sock), _1));
, this, std::weak_ptr<udp_socket>(i->udp_sock), _1));
}
return;
}
ec = boost::asio::error::operation_not_supported;
}
void session_impl::on_udp_writeable(boost::weak_ptr<udp_socket> s, error_code const& ec)
void session_impl::on_udp_writeable(std::weak_ptr<udp_socket> s, error_code const& ec)
{
COMPLETE_ASYNC("session_impl::on_udp_writeable");
if (ec) return;
boost::shared_ptr<udp_socket> sock = s.lock();
std::shared_ptr<udp_socket> sock = s.lock();
if (!sock) return;
std::list<listen_socket_t>::iterator i = std::find_if(
@ -2230,13 +2229,13 @@ namespace aux {
}
void session_impl::on_udp_packet(boost::weak_ptr<udp_socket> const& socket
void session_impl::on_udp_packet(std::weak_ptr<udp_socket> const& socket
, bool const ssl, error_code const& ec)
{
COMPLETE_ASYNC("session_impl::on_udp_packet");
if (ec)
{
boost::shared_ptr<udp_socket> s = socket.lock();
std::shared_ptr<udp_socket> 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<udp_socket> s = socket.lock();
std::shared_ptr<udp_socket> 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<tcp::acceptor> const& listener, bool ssl)
void session_impl::async_accept(std::shared_ptr<tcp::acceptor> const& listener, bool ssl)
{
TORRENT_ASSERT(!m_abort);
shared_ptr<socket_type> c(new socket_type(m_io_service));
std::shared_ptr<socket_type> c = std::make_shared<socket_type>(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<tcp::acceptor>(listener), _1, ssl));
, std::weak_ptr<tcp::acceptor>(listener), _1, ssl));
}
void session_impl::on_accept_connection(shared_ptr<socket_type> const& s
, weak_ptr<tcp::acceptor> listen_socket, error_code const& e
void session_impl::on_accept_connection(std::shared_ptr<socket_type> const& s
, std::weak_ptr<tcp::acceptor> 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<tcp::acceptor> listener = listen_socket.lock();
std::shared_ptr<tcp::acceptor> 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<socket_type> const& s)
void session_impl::on_incoming_utp_ssl(std::shared_ptr<socket_type> 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<ssl_stream<utp_stream> >()->async_accept_handshake(
s->get<ssl_stream<utp_stream>>()->async_accept_handshake(
std::bind(&session_impl::ssl_handshake, this, _1, s));
m_incoming_sockets.insert(s);
}
@ -2523,7 +2522,7 @@ namespace aux {
// -CAfile <torrent-cert>.pem -debug -connect 127.0.0.1:4433 -tls1
// -servername <hex-encoded-info-hash>
void session_impl::ssl_handshake(error_code const& ec, boost::shared_ptr<socket_type> s)
void session_impl::ssl_handshake(error_code const& ec, std::shared_ptr<socket_type> 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<socket_type> const& s)
void session_impl::incoming_connection(std::shared_ptr<socket_type> const& s)
{
TORRENT_ASSERT(is_single_thread());

View File

@ -36,10 +36,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifdef TORRENT_USE_OPENSSL
#include <boost/asio/ssl/context.hpp>
#if BOOST_VERSION >= 104700
#include <boost/asio/ssl/rfc2818_verification.hpp>
#endif
#endif
@ -137,7 +134,7 @@ namespace libtorrent
#ifdef TORRENT_USE_OPENSSL
namespace {
void on_close_socket(socket_type* s, boost::shared_ptr<void>)
void on_close_socket(socket_type* s, std::shared_ptr<void>)
{
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<void> holder)
void async_shutdown(socket_type& s, std::shared_ptr<void> holder)
{
error_code e;
@ -161,9 +158,9 @@ namespace libtorrent
#define MAYBE_ASIO_DEBUGGING
#endif
#define CASE(t) case socket_type_int_impl<ssl_stream<t> >::value: \
#define CASE(t) case socket_type_int_impl<ssl_stream<t>>::value: \
MAYBE_ASIO_DEBUGGING \
s.get<ssl_stream<t> >()->async_shutdown(std::bind(&on_close_socket, &s, holder)); \
s.get<ssl_stream<t>>()->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<ssl_stream<tcp::socket> >::value:
get<ssl_stream<tcp::socket> >()->~ssl_stream();
case socket_type_int_impl<ssl_stream<tcp::socket>>::value:
get<ssl_stream<tcp::socket>>()->~ssl_stream();
break;
case socket_type_int_impl<ssl_stream<socks5_stream> >::value:
get<ssl_stream<socks5_stream> >()->~ssl_stream();
case socket_type_int_impl<ssl_stream<socks5_stream>>::value:
get<ssl_stream<socks5_stream>>()->~ssl_stream();
break;
case socket_type_int_impl<ssl_stream<http_stream> >::value:
get<ssl_stream<http_stream> >()->~ssl_stream();
case socket_type_int_impl<ssl_stream<http_stream>>::value:
get<ssl_stream<http_stream>>()->~ssl_stream();
break;
case socket_type_int_impl<ssl_stream<utp_stream> >::value:
get<ssl_stream<utp_stream> >()->~ssl_stream();
case socket_type_int_impl<ssl_stream<utp_stream>>::value:
get<ssl_stream<utp_stream>>()->~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<ssl_stream<tcp::socket> >::value:
case socket_type_int_impl<ssl_stream<tcp::socket>>::value:
TORRENT_ASSERT(userdata);
new (reinterpret_cast<ssl_stream<tcp::socket>*>(&m_data)) ssl_stream<tcp::socket>(m_io_service
, *static_cast<ssl::context*>(userdata));
break;
case socket_type_int_impl<ssl_stream<socks5_stream> >::value:
case socket_type_int_impl<ssl_stream<socks5_stream>>::value:
TORRENT_ASSERT(userdata);
new (reinterpret_cast<ssl_stream<socks5_stream>*>(&m_data)) ssl_stream<socks5_stream>(m_io_service
, *static_cast<ssl::context*>(userdata));
break;
case socket_type_int_impl<ssl_stream<http_stream> >::value:
case socket_type_int_impl<ssl_stream<http_stream>>::value:
TORRENT_ASSERT(userdata);
new (reinterpret_cast<ssl_stream<http_stream>*>(&m_data)) ssl_stream<http_stream>(m_io_service
, *static_cast<ssl::context*>(userdata));
break;
case socket_type_int_impl<ssl_stream<utp_stream> >::value:
case socket_type_int_impl<ssl_stream<utp_stream>>::value:
TORRENT_ASSERT(userdata);
new (reinterpret_cast<ssl_stream<utp_stream>*>(&m_data)) ssl_stream<utp_stream>(m_io_service
, *static_cast<ssl::context*>(userdata));
@ -348,7 +345,7 @@ namespace libtorrent
case socket_type_int_impl<utp_stream>::value:
return get<utp_stream>()->get_close_reason();
#ifdef TORRENT_USE_OPENSSL
case socket_type_int_impl<ssl_stream<utp_stream> >::value:
case socket_type_int_impl<ssl_stream<utp_stream>>::value:
return get<ssl_stream<utp_stream> >()->lowest_layer().get_close_reason();
#endif
default: return 0;
@ -393,4 +390,3 @@ namespace libtorrent
#endif
}

View File

@ -737,7 +737,7 @@ namespace libtorrent
{
TORRENT_ASSERT(!m_url.empty());
TORRENT_ASSERT(!m_torrent_file->is_valid());
boost::shared_ptr<http_connection> conn(
std::shared_ptr<http_connection> 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<socket_type> s
= boost::make_shared<socket_type>(std::ref(m_ses.get_io_service()));
std::shared_ptr<socket_type> s
= std::make_shared<socket_type>(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<socket_type> s(new socket_type(m_ses.get_io_service()));
std::shared_ptr<socket_type> s = std::make_shared<socket_type>(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<socket_type> s = p->get_socket();
std::shared_ptr<socket_type> s = p->get_socket();
//
#define SSL(t) socket_type_int_impl<ssl_stream<t>>::value: \

View File

@ -215,7 +215,7 @@ namespace libtorrent
// UTP_LOGV("not found, new connection id:%d\n", m_new_connection);
boost::shared_ptr<socket_type> c(new (std::nothrow) socket_type(m_ios));
std::shared_ptr<socket_type> 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<ssl_stream<utp_stream> >()->next_layer();
str = &c->get<ssl_stream<utp_stream>>()->next_layer();
else
#endif
str = c->get<utp_stream>();
@ -346,4 +346,3 @@ namespace libtorrent
return impl;
}
}

View File

@ -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<http_connection> h(new http_connection(ios
, res, &::http_handler, true, 1024*1024, &::http_connect_handler));
std::shared_ptr<http_connection> h = std::make_shared<http_connection>(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);
}