Skip to content

Update boost to std #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replaced use of boost::bind with std::bind.
  • Loading branch information
glynos committed Jan 30, 2016
commit 21adf362271299af07b1e5e2f7282131998d8d5a
150 changes: 86 additions & 64 deletions boost/network/protocol/http/client/connection/async_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
#include <iterator>
#include <cstdint>
#include <boost/algorithm/string/trim.hpp>
#include <boost/array.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/asio/strand.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/assert.hpp>
#include <boost/bind/protect.hpp>
#include <boost/logic/tribool.hpp>
#include <boost/network/constants.hpp>
#include <boost/network/detail/debug.hpp>
Expand Down Expand Up @@ -102,16 +100,19 @@ struct http_async_connection
string_type host_ = host(request);
std::uint16_t source_port = request.source_port();

auto self = this->shared_from_this();
resolve_(resolver_, host_, port_,
request_strand_.wrap(boost::bind(
&this_type::handle_resolved, this_type::shared_from_this(),
host_, port_, source_port, get_body, callback, generator,
boost::arg<1>(), boost::arg<2>())));
request_strand_.wrap(
[=] (boost::system::error_code const &ec,
resolver_iterator_pair endpoint_range) {
self->handle_resolved(host_, port_, source_port, get_body,
callback, generator, ec, endpoint_range);
}));
if (timeout_ > 0) {
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
timer_.async_wait(request_strand_.wrap(
boost::bind(&this_type::handle_timeout, this_type::shared_from_this(),
boost::arg<1>())));
timer_.async_wait(request_strand_.wrap([=] (boost::system::error_code const &ec) {
self->handle_timeout(ec);
}));
}
return response_;
}
Expand Down Expand Up @@ -145,13 +146,14 @@ struct http_async_connection
// that there's still more endpoints to try connecting to.
resolver_iterator iter = boost::begin(endpoint_range);
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
auto self = this->shared_from_this();
delegate_->connect(
endpoint, host, source_port,
request_strand_.wrap(boost::bind(
&this_type::handle_connected, this_type::shared_from_this(), host,
port, source_port, get_body, callback, generator,
std::make_pair(++iter, resolver_iterator()),
placeholders::error)));
request_strand_.wrap([=] (boost::system::error_code const &ec) {
auto iter_copy = iter;
self->handle_connected(host, port, source_port, get_body, callback,
generator, std::make_pair(++iter_copy, resolver_iterator()), ec);
}));
} else {
set_errors(ec ? ec : boost::asio::error::host_not_found);
boost::iterator_range<const char*> range;
Expand All @@ -169,23 +171,27 @@ struct http_async_connection
set_errors(asio::error::timed_out);
} else if (!ec) {
BOOST_ASSERT(delegate_.get() != 0);
auto self = this->shared_from_this();
delegate_->write(
command_streambuf,
request_strand_.wrap(boost::bind(
&this_type::handle_sent_request, this_type::shared_from_this(),
get_body, callback, generator, placeholders::error,
placeholders::bytes_transferred)));
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_sent_request(get_body, callback, generator,
ec, bytes_transferred);
}));
} else {
if (!boost::empty(endpoint_range)) {
resolver_iterator iter = boost::begin(endpoint_range);
asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port);
auto self = this->shared_from_this();
delegate_->connect(
endpoint, host, source_port,
request_strand_.wrap(boost::bind(
&this_type::handle_connected, this_type::shared_from_this(),
host, port, source_port, get_body, callback, generator,
std::make_pair(++iter, resolver_iterator()),
placeholders::error)));
request_strand_.wrap([=] (boost::system::error_code const &ec) {
auto iter_copy = iter;
self->handle_connected(host, port, source_port, get_body, callback,
generator, std::make_pair(++iter_copy, resolver_iterator()),
ec);
}));
} else {
set_errors(ec ? ec : boost::asio::error::host_not_found);
boost::iterator_range<const char*> range;
Expand All @@ -211,22 +217,27 @@ struct http_async_connection
std::copy(chunk.begin(), chunk.end(),
std::ostreambuf_iterator<typename char_<Tag>::type>(
&command_streambuf));
auto self = this->shared_from_this();
delegate_->write(
command_streambuf,
request_strand_.wrap(boost::bind(
&this_type::handle_sent_request,
this_type::shared_from_this(), get_body, callback, generator,
placeholders::error, placeholders::bytes_transferred)));
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_sent_request(get_body, callback, generator,
ec, bytes_transferred);
}));
return;
}
}

auto self = this->shared_from_this();
delegate_->read_some(
boost::asio::mutable_buffers_1(this->part.data(),
this->part.size()),
request_strand_.wrap(boost::bind(
&this_type::handle_received_data, this_type::shared_from_this(),
version, get_body, callback, placeholders::error,
placeholders::bytes_transferred)));
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(version, get_body, callback,
ec, bytes_transferred);
}));
} else {
set_errors(is_timedout_ ? asio::error::timed_out : ec);
}
Expand All @@ -248,15 +259,17 @@ struct http_async_connection
(!ec || ec == boost::asio::error::eof || is_ssl_short_read_error)) {
logic::tribool parsed_ok;
size_t remainder;
auto self = this->shared_from_this();
switch (state) {
case version:
if (ec == boost::asio::error::eof) return;
parsed_ok = this->parse_version(
delegate_,
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), version, get_body, callback,
placeholders::error, placeholders::bytes_transferred)),
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(version, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);
if (!parsed_ok || indeterminate(parsed_ok)) {
return;
Expand All @@ -265,22 +278,23 @@ struct http_async_connection
if (ec == boost::asio::error::eof) return;
parsed_ok = this->parse_status(
delegate_,
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), status, get_body, callback,
placeholders::error, placeholders::bytes_transferred)),
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(status, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);
if (!parsed_ok || indeterminate(parsed_ok)) {
return;
}
case status_message:
if (ec == boost::asio::error::eof) return;
parsed_ok = this->parse_status_message(
delegate_, request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), status_message,
get_body, callback, placeholders::error,
placeholders::bytes_transferred)),
delegate_, request_strand_.wrap([=] (boost::system::error_code const &,
std::size_t bytes_transferred) {
self->handle_received_data(status_message, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);
if (!parsed_ok || indeterminate(parsed_ok)) {
return;
Expand All @@ -293,10 +307,11 @@ struct http_async_connection
// to get more data for the body is scheduled.
fusion::tie(parsed_ok, remainder) = this->parse_headers(
delegate_,
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), headers, get_body, callback,
placeholders::error, placeholders::bytes_transferred)),
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(headers, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);

if (!parsed_ok || indeterminate(parsed_ok)) {
Expand Down Expand Up @@ -335,22 +350,26 @@ struct http_async_connection
// wait before scheduling another read.
callback(make_iterator_range(begin, end), ec);

auto self = this->shared_from_this();
delegate_->read_some(
boost::asio::mutable_buffers_1(this->part.data(),
this->part.size()),
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), body, get_body, callback,
placeholders::error, placeholders::bytes_transferred)));
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}));
} else {
// Here we handle the body data ourself and append to an
// ever-growing string buffer.
auto self = this->shared_from_this();
this->parse_body(
delegate_,
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), body, get_body, callback,
placeholders::error, placeholders::bytes_transferred)),
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}),
remainder);
}
return;
Expand Down Expand Up @@ -399,23 +418,26 @@ struct http_async_connection
typename protocol_base::buffer_type::const_iterator end = begin;
std::advance(end, bytes_transferred);
callback(make_iterator_range(begin, end), ec);
auto self = this->shared_from_this();
delegate_->read_some(
boost::asio::mutable_buffers_1(this->part.data(),
this->part.size()),
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), body, get_body, callback,
placeholders::error, placeholders::bytes_transferred)));
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}));
} else {
// Here we don't have a body callback. Let's make sure that we
// deal with the remainder from the headers part in case we do
// have data that's still in the buffer.
this->parse_body(
delegate_,
request_strand_.wrap(boost::bind(
&this_type::handle_received_data,
this_type::shared_from_this(), body, get_body, callback,
placeholders::error, placeholders::bytes_transferred)),
request_strand_.wrap([=] (boost::system::error_code const &ec,
std::size_t bytes_transferred) {
self->handle_received_data(body, get_body, callback,
ec, bytes_transferred);
}),
bytes_transferred);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <cstdint>
#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>
#include <boost/network/protocol/http/client/connection/ssl_delegate.hpp>

boost::network::http::impl::ssl_delegate::ssl_delegate(
Expand Down Expand Up @@ -71,12 +70,12 @@ void boost::network::http::impl::ssl_delegate::connect(

if (always_verify_peer_)
socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
auto self = this->shared_from_this();
socket_->lowest_layer().async_connect(
endpoint,
::boost::bind(
&boost::network::http::impl::ssl_delegate::handle_connected,
boost::network::http::impl::ssl_delegate::shared_from_this(),
asio::placeholders::error, handler));
[=] (boost::system::error_code const &ec) {
self->handle_connected(ec, handler);
});
}

void boost::network::http::impl::ssl_delegate::handle_connected(
Expand Down
7 changes: 4 additions & 3 deletions boost/network/protocol/http/client/connection/sync_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ struct http_sync_connection
}
if (timeout_ > 0) {
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
timer_.async_wait(boost::bind(&this_type::handle_timeout,
this_type::shared_from_this(),
boost::arg<1>()));
auto self = this->shared_from_this();
timer_.async_wait([=] (boost::system::error_code const &ec) {
self->handle_timeout(ec);
});
}
}

Expand Down
8 changes: 4 additions & 4 deletions boost/network/protocol/http/client/connection/sync_ssl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <boost/asio/streambuf.hpp>
#include <boost/function.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/bind.hpp>
#include <boost/network/protocol/http/request.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>

Expand Down Expand Up @@ -120,9 +119,10 @@ struct https_sync_connection
}
if (timeout_ > 0) {
timer_.expires_from_now(boost::posix_time::seconds(timeout_));
timer_.async_wait(boost::bind(&this_type::handle_timeout,
this_type::shared_from_this(),
boost::arg<1>()));
auto self = this->shared_from_this();
timer_.async_wait([=] (boost::system::error_code const &ec) {
self->handle_timeout(ec);
});
}
}

Expand Down
10 changes: 4 additions & 6 deletions boost/network/protocol/http/policies/async_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <memory>
#include <functional>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/network/protocol/http/client/connection/async_base.hpp>
#include <boost/network/protocol/http/message/wrappers/protocol.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
Expand Down Expand Up @@ -77,12 +76,11 @@ struct async_connection_policy : resolver_policy<Tag>::type {
optional<string_type> const& ciphers = optional<string_type>(),
long ssl_options = 0) {
string_type protocol_ = protocol(request_);
namespace ph = std::placeholders;
connection_ptr connection_(new connection_impl(
follow_redirect_, always_verify_peer,
boost::bind(&async_connection_policy<Tag, version_major,
version_minor>::resolve,
this, boost::arg<1>(), boost::arg<2>(), boost::arg<3>(),
boost::arg<4>()),
std::bind(&async_connection_policy<Tag, version_major,
version_minor>::resolve, this, ph::_1, ph::_2, ph::_3, ph::_4),
resolver, boost::iequals(protocol_, string_type("https")), timeout_,
certificate_filename, verify_path, certificate_file, private_key_file,
ciphers, ssl_options));
Expand Down
14 changes: 7 additions & 7 deletions boost/network/protocol/http/policies/async_resolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <boost/function.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/fusion/tuple/tuple_tie.hpp>
#include <boost/bind/bind.hpp>

namespace boost {
namespace network {
Expand Down Expand Up @@ -63,12 +62,13 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {

typename resolver_type::query q(host,
std::to_string(port));
resolver_.async_resolve(q, resolver_strand_->wrap(boost::bind(
&async_resolver<Tag>::handle_resolve,
async_resolver<Tag>::shared_from_this(),
boost::to_lower_copy(host), once_resolved,
boost::asio::placeholders::error,
boost::asio::placeholders::iterator)));
auto self = this->shared_from_this();
resolver_.async_resolve(q, resolver_strand_->wrap([=] (boost::system::error_code const &ec,
resolver_iterator endpoint_iterator) {
self->handle_resolve(boost::to_lower_copy(host),
once_resolved,
ec, endpoint_iterator);
}));
}

void handle_resolve(string_type /*unused*/const &host,
Expand Down
Loading