don't allocate handlers for proxy sockets in the heap, move them instead (#1342)

don't allocate handlers for proxy sockets in the heap, move them instead
This commit is contained in:
Arvid Norberg 2016-11-19 22:56:34 -05:00 committed by GitHub
parent a59350687a
commit 13d9361da1
8 changed files with 126 additions and 139 deletions

View File

@ -88,24 +88,20 @@ public:
// 3. send HTTP CONNECT method and possibly username+password
// 4. read CONNECT response
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;
tcp::resolver::query q(m_hostname, to_string(m_port).data());
m_resolver.async_resolve(q, std::bind(
&http_stream::name_lookup, this, _1, _2, h));
&http_stream::name_lookup, this, _1, _2, handler_type(std::move(handler))));
}
private:
void name_lookup(error_code const& e, tcp::resolver::iterator i
, 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);
, handler_type& h);
void connected(error_code const& e, handler_type& h);
void handshake1(error_code const& e, handler_type& h);
void handshake2(error_code const& e, handler_type& h);
// send and receive buffer
std::vector<char> m_buffer;

View File

@ -113,34 +113,30 @@ public:
// 2. connect to SAM bridge
// 4 send command message (CONNECT/ACCEPT)
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;
tcp::resolver::query q(m_hostname, to_string(m_port).data());
m_resolver.async_resolve(q, std::bind(
&i2p_stream::do_connect, this, _1, _2, h));
&i2p_stream::do_connect, this, _1, _2, handler_type(std::move(handler))));
}
std::string name_lookup() const { return m_name_lookup; }
void set_name_lookup(char const* name) { m_name_lookup = name; }
void send_name_lookup(std::shared_ptr<handler_type> h);
void send_name_lookup(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
, 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);
, handler_type h);
void connected(error_code const& e, handler_type& h);
void start_read_line(error_code const& e, handler_type& h);
void read_line(error_code const& e, handler_type& h);
void send_connect(handler_type h);
void send_accept(handler_type h);
void send_session_create(handler_type h);
// send and receive buffer
std::vector<char> m_buffer;
@ -178,7 +174,7 @@ public:
&& m_sam_socket->is_open()
&& m_state != sam_connecting;
}
void open(std::string const& hostname, int port, i2p_stream::handler_type const& h);
void open(std::string const& hostname, int port, i2p_stream::handler_type h);
void close(error_code&);
char const* session_id() const { return m_session_id.c_str(); }
@ -191,16 +187,16 @@ private:
// explicitly disallow assignment, to silence msvc warning
i2p_connection& operator=(i2p_connection const&);
void on_sam_connect(error_code const& ec, i2p_stream::handler_type const& h
void on_sam_connect(error_code const& ec, i2p_stream::handler_type& h
, std::shared_ptr<i2p_stream>);
void do_name_lookup(std::string const& name
, name_lookup_handler const& h);
, name_lookup_handler h);
void on_name_lookup(error_code const& ec
, name_lookup_handler handler
, name_lookup_handler& handler
, std::shared_ptr<i2p_stream>);
void set_local_endpoint(error_code const& ec, char const* dest
, i2p_stream::handler_type const& h);
, i2p_stream::handler_type& h);
// to talk to i2p SAM bridge
std::shared_ptr<i2p_stream> m_sam_socket;

View File

@ -246,7 +246,7 @@ public:
protected:
bool handle_error(error_code const& e, std::shared_ptr<handler_type> const& h);
bool handle_error(error_code const& e, handler_type const& h);
tcp::socket m_sock;
std::string m_hostname;

View File

@ -122,20 +122,17 @@ public:
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("socks5_stream::connect1");
#endif
connect1(e, std::make_shared<handler_type>(handler));
handler_type h(std::move(handler));
connect1(e, h);
}
template <typename Handler>
void async_listen(tcp::endpoint const& ep, Handler const& handler)
void async_listen(tcp::endpoint const& ep, Handler handler)
{
m_command = socks5_bind;
m_remote_endpoint = ep;
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
auto h = std::make_shared<handler_type>(handler);
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("socks5_stream::name_lookup");
#endif
@ -143,7 +140,7 @@ public:
using std::placeholders::_2;
tcp::resolver::query q(m_hostname, to_string(m_port).data());
m_resolver.async_resolve(q, std::bind(
&socks5_stream::name_lookup, this, _1, _2, h));
&socks5_stream::name_lookup, this, _1, _2, handler_type(std::move(handler))));
}
void set_dst_name(std::string const& host)
@ -205,31 +202,27 @@ public:
// 3.3 send username+password
// 4. send SOCKS command message
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
auto h = std::make_shared<handler_type>(handler);
using std::placeholders::_1;
using std::placeholders::_2;
ADD_OUTSTANDING_ASYNC("socks5_stream::name_lookup");
tcp::resolver::query q(m_hostname, to_string(m_port).data());
m_resolver.async_resolve(q, std::bind(
&socks5_stream::name_lookup, this, _1, _2, h));
&socks5_stream::name_lookup, this, _1, _2, handler_type(std::move(handler))));
}
private:
void name_lookup(error_code const& e, tcp::resolver::iterator i
, 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);
, handler_type& h);
void connected(error_code const& e, handler_type& h);
void handshake1(error_code const& e, handler_type& h);
void handshake2(error_code const& e, handler_type& h);
void handshake3(error_code const& e, handler_type& h);
void handshake4(error_code const& e, handler_type& h);
void socks_connect(handler_type h);
void connect1(error_code const& e, handler_type& h);
void connect2(error_code const& e, handler_type& h);
void connect3(error_code const& e, handler_type& h);
// send and receive buffer
std::vector<char> m_buffer;

View File

@ -42,15 +42,15 @@ namespace libtorrent
{
void http_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
, std::shared_ptr<handler_type> h)
, handler_type& h)
{
if (handle_error(e, h)) return;
m_sock.async_connect(i->endpoint(), std::bind(
&http_stream::connected, this, _1, h));
&http_stream::connected, this, _1, std::move(h)));
}
void http_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
void http_stream::connected(error_code const& e, handler_type& h)
{
if (handle_error(e, h)) return;
@ -59,7 +59,7 @@ namespace libtorrent
if (m_no_connect)
{
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
return;
}
@ -82,20 +82,20 @@ namespace libtorrent
}
write_string("\r\n", p);
async_write(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&http_stream::handshake1, this, _1, h));
, std::bind(&http_stream::handshake1, this, _1, std::move(h)));
}
void http_stream::handshake1(error_code const& e, std::shared_ptr<handler_type> h)
void http_stream::handshake1(error_code const& e, handler_type& h)
{
if (handle_error(e, h)) return;
// read one byte from the socket
m_buffer.resize(1);
async_read(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&http_stream::handshake2, this, _1, h));
, std::bind(&http_stream::handshake2, this, _1, std::move(h)));
}
void http_stream::handshake2(error_code const& e, std::shared_ptr<handler_type> h)
void http_stream::handshake2(error_code const& e, handler_type& h)
{
if (handle_error(e, h)) return;
@ -124,7 +124,7 @@ namespace libtorrent
char* status = std::strchr(&m_buffer[0], ' ');
if (status == nullptr)
{
(*h)(boost::asio::error::operation_not_supported);
h(boost::asio::error::operation_not_supported);
error_code ec;
close(ec);
return;
@ -134,13 +134,13 @@ namespace libtorrent
int code = std::atoi(status);
if (code != 200)
{
(*h)(boost::asio::error::operation_not_supported);
h(boost::asio::error::operation_not_supported);
error_code ec;
close(ec);
return;
}
(*h)(e);
h(e);
std::vector<char>().swap(m_buffer);
return;
}
@ -148,7 +148,7 @@ namespace libtorrent
// read another byte from the socket
m_buffer.resize(read_pos + 1);
async_read(m_sock, boost::asio::buffer(&m_buffer[0] + read_pos, 1)
, std::bind(&http_stream::handshake2, this, _1, h));
, std::bind(&http_stream::handshake2, this, _1, std::move(h)));
}
}

View File

@ -115,7 +115,7 @@ namespace libtorrent
}
void i2p_connection::open(std::string const& s, int port
, i2p_stream::handler_type const& handler)
, i2p_stream::handler_type handler)
{
// we already seem to have a session to this SAM router
if (m_hostname == s
@ -142,11 +142,12 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("i2p_stream::on_sam_connect");
m_sam_socket->async_connect(tcp::endpoint()
, std::bind(&i2p_connection::on_sam_connect, this, _1, handler, m_sam_socket));
, std::bind(&i2p_connection::on_sam_connect, this, _1
, std::move(handler), m_sam_socket));
}
void i2p_connection::on_sam_connect(error_code const& ec
, i2p_stream::handler_type const& h, std::shared_ptr<i2p_stream>)
, i2p_stream::handler_type& h, std::shared_ptr<i2p_stream>)
{
COMPLETE_ASYNC("i2p_stream::on_sam_connect");
m_state = sam_idle;
@ -157,11 +158,12 @@ namespace libtorrent
return;
}
do_name_lookup("ME", std::bind(&i2p_connection::set_local_endpoint, this, _1, _2, h));
do_name_lookup("ME", std::bind(&i2p_connection::set_local_endpoint
, this, _1, _2, std::move(h)));
}
void i2p_connection::set_local_endpoint(error_code const& ec, char const* dest
, i2p_stream::handler_type const& h)
, i2p_stream::handler_type& h)
{
if (!ec && dest != nullptr)
m_i2p_local_endpoint = dest;
@ -175,24 +177,24 @@ namespace libtorrent
, i2p_connection::name_lookup_handler handler)
{
if (m_state == sam_idle && m_name_lookup.empty() && is_open())
do_name_lookup(name, handler);
do_name_lookup(name, std::move(handler));
else
m_name_lookup.push_back(std::make_pair(std::string(name), handler));
m_name_lookup.push_back(std::make_pair(std::string(name)
, std::move(handler)));
}
void i2p_connection::do_name_lookup(std::string const& name
, name_lookup_handler const& handler)
, name_lookup_handler handler)
{
TORRENT_ASSERT(m_state == sam_idle);
m_state = sam_name_lookup;
m_sam_socket->set_name_lookup(name.c_str());
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);
m_sam_socket->send_name_lookup(std::bind(&i2p_connection::on_name_lookup
, this, _1, std::move(handler), m_sam_socket));
}
void i2p_connection::on_name_lookup(error_code const& ec
, name_lookup_handler handler, std::shared_ptr<i2p_stream>)
, name_lookup_handler& handler, std::shared_ptr<i2p_stream>)
{
m_state = sam_idle;
@ -200,7 +202,7 @@ namespace libtorrent
if (!m_name_lookup.empty())
{
std::pair<std::string, name_lookup_handler>& nl = m_name_lookup.front();
do_name_lookup(nl.first, nl.second);
do_name_lookup(std::move(nl.first), std::move(nl.second));
m_name_lookup.pop_front();
}
@ -233,12 +235,12 @@ namespace libtorrent
}
void i2p_stream::do_connect(error_code const& e, tcp::resolver::iterator i
, std::shared_ptr<handler_type> h)
, handler_type h)
{
TORRENT_ASSERT(m_magic == 0x1337);
if (e || i == tcp::resolver::iterator())
{
(*h)(e);
h(e);
error_code ec;
close(ec);
return;
@ -246,10 +248,10 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("i2p_stream::connected");
m_sock.async_connect(i->endpoint(), std::bind(
&i2p_stream::connected, this, _1, h));
&i2p_stream::connected, this, _1, std::move(h)));
}
void i2p_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
void i2p_stream::connected(error_code const& e, handler_type& h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::connected");
@ -261,10 +263,10 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, sizeof(cmd) - 1)
, std::bind(&i2p_stream::start_read_line, this, _1, h));
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
void i2p_stream::start_read_line(error_code const& e, std::shared_ptr<handler_type> h)
void i2p_stream::start_read_line(error_code const& e, handler_type& h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::start_read_line");
@ -273,10 +275,10 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("i2p_stream::read_line");
m_buffer.resize(1);
async_read(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&i2p_stream::read_line, this, _1, h));
, std::bind(&i2p_stream::read_line, this, _1, std::move(h)));
}
void i2p_stream::read_line(error_code const& e, std::shared_ptr<handler_type> h)
void i2p_stream::read_line(error_code const& e, handler_type& h)
{
TORRENT_ASSERT(m_magic == 0x1337);
COMPLETE_ASYNC("i2p_stream::read_line");
@ -291,7 +293,7 @@ namespace libtorrent
// read another byte from the socket
m_buffer.resize(read_pos + 1);
async_read(m_sock, boost::asio::buffer(&m_buffer[read_pos], 1)
, std::bind(&i2p_stream::read_line, this, _1, h));
, std::bind(&i2p_stream::read_line, this, _1, std::move(h)));
return;
}
m_buffer[read_pos - 1] = 0;
@ -301,7 +303,7 @@ namespace libtorrent
// this is the line containing the destination
// of the incoming connection in an accept call
m_dest = &m_buffer[0];
(*h)(e);
h(e);
std::vector<char>().swap(m_buffer);
return;
}
@ -410,23 +412,23 @@ namespace libtorrent
switch (m_command)
{
case cmd_create_session:
send_session_create(h);
send_session_create(std::move(h));
break;
case cmd_accept:
send_accept(h);
send_accept(std::move(h));
break;
case cmd_connect:
send_connect(h);
send_connect(std::move(h));
break;
default:
(*h)(e);
h(e);
std::vector<char>().swap(m_buffer);
}
break;
case read_connect_response:
case read_session_create_response:
case read_name_lookup_response:
(*h)(ec);
h(ec);
std::vector<char>().swap(m_buffer);
break;
case read_accept_response:
@ -445,7 +447,7 @@ namespace libtorrent
return;
}
void i2p_stream::send_connect(std::shared_ptr<handler_type> h)
void i2p_stream::send_connect(handler_type h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_connect_response;
@ -454,10 +456,10 @@ namespace libtorrent
, m_id, m_dest.c_str());
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
, std::bind(&i2p_stream::start_read_line, this, _1, h));
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
void i2p_stream::send_accept(std::shared_ptr<handler_type> h)
void i2p_stream::send_accept(handler_type h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_accept_response;
@ -465,10 +467,10 @@ namespace libtorrent
int size = std::snprintf(cmd, sizeof(cmd), "STREAM ACCEPT ID=%s\n", m_id);
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
, std::bind(&i2p_stream::start_read_line, this, _1, h));
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
void i2p_stream::send_session_create(std::shared_ptr<handler_type> h)
void i2p_stream::send_session_create(handler_type h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_session_create_response;
@ -477,10 +479,10 @@ namespace libtorrent
, m_id);
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
, std::bind(&i2p_stream::start_read_line, this, _1, h));
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
void i2p_stream::send_name_lookup(std::shared_ptr<handler_type> h)
void i2p_stream::send_name_lookup(handler_type h)
{
TORRENT_ASSERT(m_magic == 0x1337);
m_state = read_name_lookup_response;
@ -488,7 +490,7 @@ namespace libtorrent
int size = std::snprintf(cmd, sizeof(cmd), "NAMING LOOKUP NAME=%s\n", m_name_lookup.c_str());
ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line");
async_write(m_sock, boost::asio::buffer(cmd, size)
, std::bind(&i2p_stream::start_read_line, this, _1, h));
, std::bind(&i2p_stream::start_read_line, this, _1, std::move(h)));
}
}

View File

@ -43,10 +43,10 @@ namespace libtorrent
proxy_base::~proxy_base() = default;
bool proxy_base::handle_error(error_code const& e, std::shared_ptr<handler_type> const& h)
bool proxy_base::handle_error(error_code const& e, handler_type const& h)
{
if (!e) return false;
(*h)(e);
h(e);
error_code ec;
close(ec);
return true;

View File

@ -131,7 +131,7 @@ namespace libtorrent
}
void socks5_stream::name_lookup(error_code const& e, tcp::resolver::iterator i
, std::shared_ptr<handler_type> h)
, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::name_lookup");
if (handle_error(e, h)) return;
@ -147,10 +147,10 @@ namespace libtorrent
// target endpoint is of the proxy
ADD_OUTSTANDING_ASYNC("socks5_stream::connected");
m_sock.async_connect(i->endpoint(), std::bind(
&socks5_stream::connected, this, _1, h));
&socks5_stream::connected, this, _1, std::move(h)));
}
void socks5_stream::connected(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::connected(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::connected");
if (handle_error(e, h)) return;
@ -175,19 +175,19 @@ namespace libtorrent
}
ADD_OUTSTANDING_ASYNC("socks5_stream::handshake1");
async_write(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::handshake1, this, _1, h));
, std::bind(&socks5_stream::handshake1, this, _1, std::move(h)));
}
else if (m_version == 4)
{
socks_connect(h);
socks_connect(std::move(h));
}
else
{
(*h)(socks_error::unsupported_version);
h(socks_error::unsupported_version);
}
}
void socks5_stream::handshake1(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::handshake1(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::handshake1");
if (handle_error(e, h)) return;
@ -195,10 +195,10 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("socks5_stream::handshake2");
m_buffer.resize(2);
async_read(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::handshake2, this, _1, h));
, std::bind(&socks5_stream::handshake2, this, _1, std::move(h)));
}
void socks5_stream::handshake2(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::handshake2(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::handshake2");
if (handle_error(e, h)) return;
@ -211,19 +211,19 @@ namespace libtorrent
if (version < m_version)
{
(*h)(socks_error::unsupported_version);
h(socks_error::unsupported_version);
return;
}
if (method == 0)
{
socks_connect(h);
socks_connect(std::move(h));
}
else if (method == 2)
{
if (m_user.empty())
{
(*h)(socks_error::username_required);
h(socks_error::username_required);
return;
}
@ -240,17 +240,17 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("socks5_stream::handshake3");
async_write(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::handshake3, this, _1, h));
, std::bind(&socks5_stream::handshake3, this, _1, std::move(h)));
}
else
{
(*h)(socks_error::unsupported_authentication_method);
h(socks_error::unsupported_authentication_method);
return;
}
}
void socks5_stream::handshake3(error_code const& e
, std::shared_ptr<handler_type> h)
, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::handshake3");
if (handle_error(e, h)) return;
@ -258,11 +258,11 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("socks5_stream::handshake4");
m_buffer.resize(2);
async_read(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::handshake4, this, _1, h));
, std::bind(&socks5_stream::handshake4, this, _1, std::move(h)));
}
void socks5_stream::handshake4(error_code const& e
, std::shared_ptr<handler_type> h)
, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::handshake4");
if (handle_error(e, h)) return;
@ -275,21 +275,21 @@ namespace libtorrent
if (version != 1)
{
(*h)(socks_error::unsupported_authentication_version);
h(socks_error::unsupported_authentication_version);
return;
}
if (status != 0)
{
(*h)(socks_error::authentication_error);
h(socks_error::authentication_error);
return;
}
std::vector<char>().swap(m_buffer);
socks_connect(h);
socks_connect(std::move(h));
}
void socks5_stream::socks_connect(std::shared_ptr<handler_type> h)
void socks5_stream::socks_connect(handler_type h)
{
using namespace libtorrent::detail;
@ -327,7 +327,7 @@ namespace libtorrent
// SOCKS4 only supports IPv4
if (!m_remote_endpoint.address().is_v4())
{
(*h)(boost::asio::error::address_family_not_supported);
h(boost::asio::error::address_family_not_supported);
return;
}
m_buffer.resize(m_user.size() + 9);
@ -342,16 +342,16 @@ namespace libtorrent
}
else
{
(*h)(socks_error::unsupported_version);
h(socks_error::unsupported_version);
return;
}
ADD_OUTSTANDING_ASYNC("socks5_stream::connect1");
async_write(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::connect1, this, _1, h));
, std::bind(&socks5_stream::connect1, this, _1, std::move(h)));
}
void socks5_stream::connect1(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::connect1(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::connect1");
if (handle_error(e, h)) return;
@ -363,10 +363,10 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("socks5_stream::connect2");
async_read(m_sock, boost::asio::buffer(m_buffer)
, std::bind(&socks5_stream::connect2, this, _1, h));
, std::bind(&socks5_stream::connect2, this, _1, std::move(h)));
}
void socks5_stream::connect2(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::connect2(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::connect2");
if (handle_error(e, h)) return;
@ -381,7 +381,7 @@ namespace libtorrent
{
if (version < m_version)
{
(*h)(socks_error::unsupported_version);
h(socks_error::unsupported_version);
return;
}
if (response != 0)
@ -397,7 +397,7 @@ namespace libtorrent
case 7: ec = socks_error::command_not_supported; break;
case 8: ec = boost::asio::error::address_family_not_supported; break;
}
(*h)(ec);
h(ec);
return;
}
p += 1; // reserved
@ -418,12 +418,12 @@ namespace libtorrent
m_remote_endpoint = parse_endpoint(m_buffer, m_version);
}
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
}
else
{
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
}
return;
}
@ -440,7 +440,7 @@ namespace libtorrent
}
else
{
(*h)(boost::asio::error::address_family_not_supported);
h(boost::asio::error::address_family_not_supported);
return;
}
m_buffer.resize(m_buffer.size() + extra_bytes);
@ -448,13 +448,13 @@ namespace libtorrent
ADD_OUTSTANDING_ASYNC("socks5_stream::connect3");
TORRENT_ASSERT(extra_bytes > 0);
async_read(m_sock, boost::asio::buffer(&m_buffer[m_buffer.size() - extra_bytes], extra_bytes)
, std::bind(&socks5_stream::connect3, this, _1, h));
, std::bind(&socks5_stream::connect3, this, _1, std::move(h)));
}
else if (m_version == 4)
{
if (version != 0)
{
(*h)(socks_error::general_failure);
h(socks_error::general_failure);
return;
}
@ -473,12 +473,12 @@ namespace libtorrent
m_remote_endpoint = parse_endpoint(m_buffer, m_version);
}
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
}
else
{
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
}
return;
}
@ -490,11 +490,11 @@ namespace libtorrent
case 92: ec = socks_error::no_identd; break;
case 93: ec = socks_error::identd_error; break;
}
(*h)(ec);
h(ec);
}
}
void socks5_stream::connect3(error_code const& e, std::shared_ptr<handler_type> h)
void socks5_stream::connect3(error_code const& e, handler_type& h)
{
COMPLETE_ASYNC("socks5_stream::connect3");
using namespace libtorrent::detail;
@ -514,6 +514,6 @@ namespace libtorrent
}
}
std::vector<char>().swap(m_buffer);
(*h)(e);
h(e);
}
}