more use of std::shared_ptr (#1009)

more std::shared_ptr transition
This commit is contained in:
Alden Torres 2016-08-18 17:08:40 -04:00 committed by Arvid Norberg
parent 5789b02e1b
commit 9fd83aaa10
19 changed files with 72 additions and 109 deletions

View File

@ -78,6 +78,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/entry.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/io.hpp" // for write_string
#include "libtorrent/string_util.hpp" // for is_digit
namespace libtorrent
{

View File

@ -33,7 +33,6 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_ERROR_HPP_INCLUDED
#define TORRENT_ERROR_HPP_INCLUDED
#include <boost/version.hpp>
#include "libtorrent/config.hpp"
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN

View File

@ -34,18 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_ERROR_CODE_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include "libtorrent/string_util.hpp" // for allocate_string_copy
#include "libtorrent/aux_/disable_warnings_push.hpp"
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
// asio assumes that the windows error codes are defined already
#include <winsock2.h>
#endif
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent

View File

@ -33,13 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_HTTP_STREAM_HPP_INCLUDED
#define TORRENT_HTTP_STREAM_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/function/function1.hpp>
#include <functional>
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/proxy_base.hpp"
#include "libtorrent/string_util.hpp"
@ -96,7 +90,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;
using std::placeholders::_2;
@ -108,10 +102,10 @@ public:
private:
void name_lookup(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h);
void connected(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake1(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake2(error_code const& e, boost::shared_ptr<handler_type> h);
, std::shared_ptr<handler_type> h);
void connected(error_code const& e, std::shared_ptr<handler_type> h);
void handshake1(error_code const& e, std::shared_ptr<handler_type> h);
void handshake2(error_code const& e, std::shared_ptr<handler_type> h);
// send and receive buffer
std::vector<char> m_buffer;

View File

@ -37,12 +37,6 @@ POSSIBILITY OF SUCH DAMAGE.
#if TORRENT_USE_I2P
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <list>
#include <string>
#include <vector>
@ -115,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;
using std::placeholders::_2;
@ -127,20 +121,20 @@ public:
std::string name_lookup() const { return m_name_lookup; }
void set_name_lookup(char const* name) { m_name_lookup = name; }
void send_name_lookup(boost::shared_ptr<handler_type> h);
void send_name_lookup(std::shared_ptr<handler_type> h);
private:
// explicitly disallow assignment, to silence msvc warning
i2p_stream& operator=(i2p_stream const&);
void do_connect(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h);
void connected(error_code const& e, boost::shared_ptr<handler_type> h);
void start_read_line(error_code const& e, boost::shared_ptr<handler_type> h);
void read_line(error_code const& e, boost::shared_ptr<handler_type> h);
void send_connect(boost::shared_ptr<handler_type> h);
void send_accept(boost::shared_ptr<handler_type> h);
void send_session_create(boost::shared_ptr<handler_type> h);
, std::shared_ptr<handler_type> h);
void connected(error_code const& e, std::shared_ptr<handler_type> h);
void start_read_line(error_code const& e, std::shared_ptr<handler_type> h);
void read_line(error_code const& e, std::shared_ptr<handler_type> h);
void send_connect(std::shared_ptr<handler_type> h);
void send_accept(std::shared_ptr<handler_type> h);
void send_session_create(std::shared_ptr<handler_type> h);
// send and receive buffer
std::vector<char> m_buffer;
@ -192,18 +186,18 @@ private:
i2p_connection& operator=(i2p_connection const&);
void on_sam_connect(error_code const& ec, i2p_stream::handler_type const& h
, boost::shared_ptr<i2p_stream>);
, std::shared_ptr<i2p_stream>);
void do_name_lookup(std::string const& name
, name_lookup_handler const& h);
void on_name_lookup(error_code const& ec
, name_lookup_handler handler
, boost::shared_ptr<i2p_stream>);
, std::shared_ptr<i2p_stream>);
void set_local_endpoint(error_code const& ec, char const* dest
, i2p_stream::handler_type const& h);
// to talk to i2p SAM bridge
boost::shared_ptr<i2p_stream> m_sam_socket;
std::shared_ptr<i2p_stream> m_sam_socket;
std::string m_hostname;
int m_port;

View File

@ -55,4 +55,3 @@ namespace libtorrent
}
#endif // TORRENT_PEER_REQUEST_HPP_INCLUDED

View File

@ -39,11 +39,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/address.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/function/function1.hpp>
#include <boost/shared_ptr.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent {
class proxy_base : boost::noncopyable
@ -249,7 +244,7 @@ public:
protected:
bool handle_error(error_code const& e, boost::shared_ptr<handler_type> const& h);
bool handle_error(error_code const& e, std::shared_ptr<handler_type> const& h);
tcp::socket m_sock;
std::string m_hostname;
@ -264,4 +259,3 @@ protected:
}
#endif

View File

@ -33,19 +33,13 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_SOCKS5_STREAM_HPP_INCLUDED
#define TORRENT_SOCKS5_STREAM_HPP_INCLUDED
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include <functional>
#include "libtorrent/proxy_base.hpp"
#include "libtorrent/broadcast_socket.hpp" // for is_ip_address
#include "libtorrent/assert.hpp"
#include "libtorrent/debug.hpp"
#include "libtorrent/string_util.hpp" // for to_string
namespace libtorrent {
namespace socks_error {
@ -122,7 +116,7 @@ public:
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("socks5_stream::connect1");
#endif
connect1(e, boost::make_shared<handler_type>(handler));
connect1(e, std::make_shared<handler_type>(handler));
}
template <typename Handler>
@ -133,8 +127,8 @@ public:
m_remote_endpoint = ep;
// to avoid unnecessary copying of the handler,
// store it in a shaed_ptr
boost::shared_ptr<handler_type> h(new handler_type(handler));
// store it in a shared_ptr
std::shared_ptr<handler_type> h(new handler_type(handler));
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("socks5_stream::name_lookup");
@ -206,8 +200,8 @@ public:
// 4. send SOCKS command message
// to avoid unnecessary copying of the handler,
// store it in a shaed_ptr
boost::shared_ptr<handler_type> h(new handler_type(handler));
// store it in a shared_ptr
std::shared_ptr<handler_type> h(new handler_type(handler));
using std::placeholders::_1;
using std::placeholders::_2;
@ -220,16 +214,16 @@ public:
private:
void name_lookup(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h);
void connected(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake1(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake2(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake3(error_code const& e, boost::shared_ptr<handler_type> h);
void handshake4(error_code const& e, boost::shared_ptr<handler_type> h);
void socks_connect(boost::shared_ptr<handler_type> h);
void connect1(error_code const& e, boost::shared_ptr<handler_type> h);
void connect2(error_code const& e, boost::shared_ptr<handler_type> h);
void connect3(error_code const& e, boost::shared_ptr<handler_type> h);
, std::shared_ptr<handler_type> h);
void connected(error_code const& e, std::shared_ptr<handler_type> h);
void handshake1(error_code const& e, std::shared_ptr<handler_type> h);
void handshake2(error_code const& e, std::shared_ptr<handler_type> h);
void handshake3(error_code const& e, std::shared_ptr<handler_type> h);
void handshake4(error_code const& e, std::shared_ptr<handler_type> h);
void socks_connect(std::shared_ptr<handler_type> h);
void connect1(error_code const& e, std::shared_ptr<handler_type> h);
void connect2(error_code const& e, std::shared_ptr<handler_type> h);
void connect3(error_code const& e, std::shared_ptr<handler_type> h);
// send and receive buffer
std::vector<char> m_buffer;
@ -265,4 +259,3 @@ namespace boost { namespace system {
} }
#endif

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/string_util.hpp" // for is_space
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/aux_/session_settings.hpp"
@ -131,4 +132,3 @@ namespace libtorrent
}
}

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/storage.hpp"
#include "libtorrent/disk_io_thread.hpp"
#include "libtorrent/string_util.hpp" // for allocate_string_copy
#include "libtorrent/disk_buffer_holder.hpp"
#include "libtorrent/alloca.hpp"
#include "libtorrent/invariant_check.hpp"

View File

@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bdecode.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/hex.hpp"
#include "libtorrent/string_util.hpp"
namespace libtorrent
{

View File

@ -63,6 +63,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/alloca.hpp"
#include "libtorrent/file.hpp"
#include "libtorrent/string_util.hpp"
#include "libtorrent/aux_/max_path.hpp" // for TORRENT_MAX_PATH
#include <cstring>

View File

@ -38,10 +38,9 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/http_parser.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/parse_url.hpp" // for parse_url_components
#include "libtorrent/string_util.hpp" // for allocate_string_copy
#include "libtorrent/aux_/escape_string.hpp" // for read_until
using namespace libtorrent;
namespace libtorrent
{
@ -577,4 +576,3 @@ restart_response:
return size;
}
}

View File

@ -42,7 +42,7 @@ namespace libtorrent
{
void http_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h)
, std::shared_ptr<handler_type> h)
{
if (handle_error(e, h)) return;
@ -50,7 +50,7 @@ namespace libtorrent
&http_stream::connected, this, _1, h));
}
void http_stream::connected(error_code const& e, boost::shared_ptr<handler_type> h)
void http_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
{
if (handle_error(e, h)) return;
@ -85,7 +85,7 @@ namespace libtorrent
, std::bind(&http_stream::handshake1, this, _1, h));
}
void http_stream::handshake1(error_code const& e, boost::shared_ptr<handler_type> h)
void http_stream::handshake1(error_code const& e, std::shared_ptr<handler_type> h)
{
if (handle_error(e, h)) return;
@ -95,7 +95,7 @@ namespace libtorrent
, std::bind(&http_stream::handshake2, this, _1, h));
}
void http_stream::handshake2(error_code const& e, boost::shared_ptr<handler_type> h)
void http_stream::handshake2(error_code const& e, std::shared_ptr<handler_type> h)
{
if (handle_error(e, h)) return;

View File

@ -145,7 +145,8 @@ namespace libtorrent
, std::bind(&i2p_connection::on_sam_connect, this, _1, handler, m_sam_socket));
}
void i2p_connection::on_sam_connect(error_code const& ec, i2p_stream::handler_type const& h, boost::shared_ptr<i2p_stream>)
void i2p_connection::on_sam_connect(error_code const& ec
, i2p_stream::handler_type const& h, std::shared_ptr<i2p_stream>)
{
COMPLETE_ASYNC("i2p_stream::on_sam_connect");
m_state = sam_idle;
@ -185,13 +186,13 @@ namespace libtorrent
TORRENT_ASSERT(m_state == sam_idle);
m_state = sam_name_lookup;
m_sam_socket->set_name_lookup(name.c_str());
boost::shared_ptr<i2p_stream::handler_type> h(new i2p_stream::handler_type(
std::bind(&i2p_connection::on_name_lookup, this, _1, handler, m_sam_socket)));
auto h = std::make_shared<i2p_stream::handler_type>(
std::bind(&i2p_connection::on_name_lookup, this, _1, handler, m_sam_socket));
m_sam_socket->send_name_lookup(h);
}
void i2p_connection::on_name_lookup(error_code const& ec
, name_lookup_handler handler, boost::shared_ptr<i2p_stream>)
, name_lookup_handler handler, std::shared_ptr<i2p_stream>)
{
m_state = sam_idle;
@ -232,7 +233,7 @@ namespace libtorrent
}
void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h)
, std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
if (e || i == tcp::resolver::iterator())
@ -248,7 +249,7 @@ namespace libtorrent
&i2p_stream::connected, this, _1, h));
}
void i2p_stream::connected(error_code const& e, boost::shared_ptr<handler_type> h)
void i2p_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::connected");
@ -263,7 +264,7 @@ namespace libtorrent
, std::bind(&i2p_stream::start_read_line, this, _1, h));
}
void i2p_stream::start_read_line(error_code const& e, boost::shared_ptr<handler_type> h)
void i2p_stream::start_read_line(error_code const& e, std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::start_read_line");
@ -275,7 +276,7 @@ namespace libtorrent
, std::bind(&i2p_stream::read_line, this, _1, h));
}
void i2p_stream::read_line(error_code const& e, boost::shared_ptr<handler_type> h)
void i2p_stream::read_line(error_code const& e, std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::read_line");
@ -444,7 +445,7 @@ namespace libtorrent
return;
}
void i2p_stream::send_connect(boost::shared_ptr<handler_type> h)
void i2p_stream::send_connect(std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_connect_response;
@ -456,7 +457,7 @@ namespace libtorrent
, std::bind(&i2p_stream::start_read_line, this, _1, h));
}
void i2p_stream::send_accept(boost::shared_ptr<handler_type> h)
void i2p_stream::send_accept(std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_accept_response;
@ -467,7 +468,7 @@ namespace libtorrent
, std::bind(&i2p_stream::start_read_line, this, _1, h));
}
void i2p_stream::send_session_create(boost::shared_ptr<handler_type> h)
void i2p_stream::send_session_create(std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_session_create_response;
@ -479,7 +480,7 @@ namespace libtorrent
, std::bind(&i2p_stream::start_read_line, this, _1, h));
}
void i2p_stream::send_name_lookup(boost::shared_ptr<handler_type> h)
void i2p_stream::send_name_lookup(std::shared_ptr<handler_type> h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_name_lookup_response;
@ -492,4 +493,3 @@ namespace libtorrent
}
#endif

View File

@ -30,9 +30,11 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/parse_url.hpp"
#include <algorithm>
#include "libtorrent/parse_url.hpp"
#include "libtorrent/string_util.hpp"
namespace libtorrent
{
@ -131,4 +133,3 @@ exit:
}
}

View File

@ -43,7 +43,7 @@ namespace libtorrent
proxy_base::~proxy_base() = default;
bool proxy_base::handle_error(error_code const& e, boost::shared_ptr<handler_type> const& h)
bool proxy_base::handle_error(error_code const& e, std::shared_ptr<handler_type> const& h)
{
if (!e) return false;
(*h)(e);
@ -52,4 +52,3 @@ namespace libtorrent
return true;
}
}

View File

@ -31,11 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/socks5_stream.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/socket_io.hpp"
#include <functional>
using namespace std::placeholders;
namespace libtorrent
@ -134,7 +131,7 @@ namespace libtorrent
}
void socks5_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
, boost::shared_ptr<handler_type> h)
, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::name_lookup");
if (handle_error(e, h)) return;
@ -153,7 +150,7 @@ namespace libtorrent
&socks5_stream::connected, this, _1, h));
}
void socks5_stream::connected(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::connected");
if (handle_error(e, h)) return;
@ -190,7 +187,7 @@ namespace libtorrent
}
}
void socks5_stream::handshake1(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::handshake1(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::handshake1");
if (handle_error(e, h)) return;
@ -201,7 +198,7 @@ namespace libtorrent
, std::bind(&socks5_stream::handshake2, this, _1, h));
}
void socks5_stream::handshake2(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::handshake2(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::handshake2");
if (handle_error(e, h)) return;
@ -253,7 +250,7 @@ namespace libtorrent
}
void socks5_stream::handshake3(error_code const& e
, boost::shared_ptr<handler_type> h)
, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::handshake3");
if (handle_error(e, h)) return;
@ -265,7 +262,7 @@ namespace libtorrent
}
void socks5_stream::handshake4(error_code const& e
, boost::shared_ptr<handler_type> h)
, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::handshake4");
if (handle_error(e, h)) return;
@ -292,7 +289,7 @@ namespace libtorrent
socks_connect(h);
}
void socks5_stream::socks_connect(boost::shared_ptr<handler_type> h)
void socks5_stream::socks_connect(std::shared_ptr<handler_type> h)
{
using namespace libtorrent::detail;
@ -354,7 +351,7 @@ namespace libtorrent
, std::bind(&socks5_stream::connect1, this, _1, h));
}
void socks5_stream::connect1(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::connect1(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::connect1");
if (handle_error(e, h)) return;
@ -369,7 +366,7 @@ namespace libtorrent
, std::bind(&socks5_stream::connect2, this, _1, h));
}
void socks5_stream::connect2(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::connect2(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::connect2");
if (handle_error(e, h)) return;
@ -497,7 +494,7 @@ namespace libtorrent
}
}
void socks5_stream::connect3(error_code const& e, boost::shared_ptr<handler_type> h)
void socks5_stream::connect3(error_code const& e, std::shared_ptr<handler_type> h)
{
COMPLETE_ASYNC("socks5_stream::connect3");
using namespace libtorrent::detail;
@ -520,4 +517,3 @@ namespace libtorrent
(*h)(e);
}
}

View File

@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/file.hpp"
#include "libtorrent/string_util.hpp" // for split_string
#include "test.hpp"
#include <cstring> // for std::strcmp
#include <vector>
@ -392,4 +393,3 @@ TORRENT_TEST(coalesce_buffer)
TEST_CHECK(std::strcmp(test_buf2, "foobar") == 0);
f.close();
}