more use of std::make_shared, fixing warnings of over-aligned

This commit is contained in:
Alden Torres 2016-11-17 14:34:49 -05:00 committed by Arvid Norberg
parent 0a31e26344
commit 4c7e24ea35
13 changed files with 34 additions and 38 deletions

View File

@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ALLOCATING_HANDLER_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/error_code.hpp"
#include <type_traits>

View File

@ -90,7 +90,7 @@ public:
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
std::shared_ptr<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;

View File

@ -115,7 +115,7 @@ public:
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
std::shared_ptr<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;

View File

@ -41,11 +41,11 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent {
class proxy_base : boost::noncopyable
class proxy_base
{
public:
typedef std::function<void(error_code const&)> handler_type;
using handler_type = std::function<void(error_code const&)>;
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)
{

View File

@ -134,7 +134,7 @@ public:
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
std::shared_ptr<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(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<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;

View File

@ -90,7 +90,7 @@ public:
SSL* native_handle() { return m_sock.native_handle(); }
typedef std::function<void(error_code const&)> handler_type;
using handler_type = std::function<void(error_code const&)>;
template <class Handler>
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<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(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<handler_type> h(new handler_type(handler));
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
m_sock.async_handshake(ssl::stream_base::server
, std::bind(&ssl_stream::handshake, this, _1, h));

View File

@ -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

View File

@ -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<http_connection>(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

View File

@ -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<dht::get_peers> 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<dht::obfuscated_get_peers>(*this, info_hash, dcallback, ncallback, noseeds)
: std::make_shared<dht::get_peers>(*this, info_hash, dcallback, ncallback, noseeds);
ta->start();
}

View File

@ -2061,7 +2061,7 @@ namespace aux {
if (m_i2p_listen_socket) return;
m_i2p_listen_socket = std::shared_ptr<socket_type>(new socket_type(m_io_service));
m_i2p_listen_socket = std::make_shared<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);

View File

@ -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(

View File

@ -8538,7 +8538,7 @@ namespace libtorrent
state_updated();
std::shared_ptr<entry> rd(new entry);
auto rd = std::make_shared<entry>();
write_resume_data(*rd);
alerts().emplace_alert<save_resume_data_alert>(rd, get_handle());
}

View File

@ -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<http_connection>(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<http_connection>(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<http_connection>(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<http_connection>(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<http_connection>(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), "<?xml version=\"1.0\"?>\n"
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"