Skip to content

Replacing boost::bind and boost::enable_shared_form_this by std counterparts #230

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 4 commits into from
Apr 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions concurrency/test/thread_pool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include <gtest/gtest.h>
#include <network/concurrency/thread_pool.hpp>
#include <boost/bind.hpp>
// #include <boost/bind.hpp>
#include <functional>

using network::concurrency::thread_pool;

Expand Down Expand Up @@ -37,8 +38,8 @@ TEST(concurrency_test, post_work) {
foo instance;
{
thread_pool pool;
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 1)));
ASSERT_NO_THROW(pool.post(boost::bind(&foo::bar, &instance, 2)));
ASSERT_NO_THROW(pool.post(std::bind(&foo::bar, &instance, 1)));
ASSERT_NO_THROW(pool.post(std::bind(&foo::bar, &instance, 2)));
// require that pool is destroyed here, RAII baby
}
ASSERT_EQ(instance.val(), 3);
Expand Down
4 changes: 2 additions & 2 deletions contrib/http_examples/http/fileserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct file_cache {

};

struct connection_handler : boost::enable_shared_from_this<connection_handler> {
struct connection_handler : std::enable_shared_from_this<connection_handler> {
explicit connection_handler(file_cache& cache) : file_cache_(cache) {}

void operator()(std::string const& path,
Expand Down Expand Up @@ -143,7 +143,7 @@ struct connection_handler : boost::enable_shared_from_this<connection_handler> {
connection->write(boost::asio::const_buffers_1(
static_cast<char const*>(mmaped_region.first) + offset,
rightmost_bound),
boost::bind(&connection_handler::handle_chunk,
std::bind(&connection_handler::handle_chunk,
connection_handler::shared_from_this(),
mmaped_region,
rightmost_bound,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,18 @@ struct http_async_connection_pimpl
boost::system::error_code const& ec,
std::size_t bytes_transferred) {
NETWORK_MESSAGE("http_async_connection_pimpl::handle_received_data(...)");
#ifdef NETWORK_ENABLE_HTTPS
// Okay, there's some weirdness with Boost.Asio's handling of SSL errors
// so we need to do some acrobatics to make sure that we're handling the
// short-read errors correctly. This is such a PITA that we have to deal
// with this here.
static long short_read_error = 335544539;
constexpr static long short_read_error = 335544539;
bool is_short_read_error =
#ifdef NETWORK_ENABLE_HTTPS
ec.category() == boost::asio::error::ssl_category &&
ec.value() == short_read_error
(ec.category() == boost::asio::error::ssl_category) &&
(ec.value() == short_read_error);
#else
false
constexpr bool is_short_read_error = false;
#endif
;
if (!ec || ec == boost::asio::error::eof || is_short_read_error) {
NETWORK_MESSAGE("processing data chunk, no error encountered so far...");
boost::logic::tribool parsed_ok;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ struct connection_delegate_factory {
virtual ~connection_delegate_factory();

private:
connection_delegate_factory(connection_delegate_factory const&); // = delete
connection_delegate_factory& operator=(
connection_delegate_factory); // = delete
connection_delegate_factory(connection_delegate_factory const &) = delete;
connection_delegate_factory &operator=(connection_delegate_factory) = delete;
};

} // namespace http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ connection_delegate_factory::connection_delegate_ptr connection_delegate_factory
if (https) {
#ifdef NETWORK_ENABLE_HTTPS
NETWORK_MESSAGE("creating an SSL delegate");
delegate.reset(new ssl_delegate(service, options));
std::shared_ptr<ssl_delegate> delegate_ptr(new ssl_delegate(service, options));
delegate = std::move(delegate_ptr);
#else
NETWORK_MESSAGE("creating an SSL delegate, but not supported");
BOOST_THROW_EXCEPTION(std::runtime_error("HTTPS not supported."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ struct normal_delegate : connection_delegate {
boost::asio::io_service& service_;
std::unique_ptr<boost::asio::ip::tcp::socket> socket_;

normal_delegate(normal_delegate const&); // = delete
normal_delegate& operator=(normal_delegate); // = delete
normal_delegate(normal_delegate const&) = delete;
normal_delegate& operator=(normal_delegate) = delete;
};

} // namespace http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <boost/asio/ssl.hpp>
#include <network/protocol/http/client/connection/connection_delegate.hpp>
#include <network/protocol/http/client/options.hpp>
#include <boost/enable_shared_from_this.hpp>

namespace boost {
namespace asio {
Expand All @@ -23,7 +22,7 @@ namespace network {
namespace http {

struct ssl_delegate : connection_delegate,
boost::enable_shared_from_this<ssl_delegate> {
std::enable_shared_from_this<ssl_delegate> {
ssl_delegate(boost::asio::io_service& service, client_options const& options);

virtual void connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <network/protocol/http/client/options.hpp>
#include <network/protocol/http/client/connection/ssl_delegate.hpp>
#include <boost/asio/placeholders.hpp>
#include <functional>
#include <network/detail/debug.hpp>

network::http::ssl_delegate::ssl_delegate(boost::asio::io_service& service,
Expand Down Expand Up @@ -48,8 +47,7 @@ void network::http::ssl_delegate::connect(
} else {
NETWORK_MESSAGE("not verifying peer");
context_->set_default_verify_paths();
context_->set_verify_mode(boost::asio::ssl::context::verify_peer);
context_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host));
context_->set_verify_mode(boost::asio::ssl::context::verify_none);
}
socket_.reset(new boost::asio::ssl::stream<
boost::asio::ip::tcp::socket>(service_, *context_));
Expand Down
4 changes: 2 additions & 2 deletions http/src/network/protocol/http/policies/async_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/enable_shared_from_this.hpp>
// #include <boost/enable_shared_from_this.hpp>
#include <boost/tuple/tuple.hpp>
#include <functional>
#include <functional>
Expand Down Expand Up @@ -47,7 +47,7 @@ struct simple_async_connection_manager : connection_manager {
struct http_1_1_async_connection;

struct http_1_1_async_connection_manager : connection_manager,
enable_shared_from_this<http_1_1_async_connection_manager> {
std::enable_shared_from_this<http_1_1_async_connection_manager> {
http_1_1_async_connection_manager(bool cache_resolved,
bool follow_redirects,
optional<std::string> openssl_certificate,
Expand Down
25 changes: 13 additions & 12 deletions http/src/network/protocol/http/server/connection/async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#include <vector>
#include <iterator>
#include <mutex>
#include <boost/bind.hpp>
// #include <boost/bind.hpp>
#include <functional>
#include <network/constants.hpp>

#ifndef NETWORK_HTTP_SERVER_CONNECTION_HEADER_BUFFER_MAX_SIZE
Expand Down Expand Up @@ -213,7 +214,7 @@ class async_server_connection
}

write_headers_only(
boost::bind(&async_server_connection::do_nothing,
std::bind(&async_server_connection::do_nothing,
async_server_connection::shared_from_this()));
}

Expand Down Expand Up @@ -279,7 +280,7 @@ class async_server_connection
input_range input = boost::make_iterator_range(new_start,
read_buffer_.end());
thread_pool()
.post(boost::bind(callback,
.post(std::bind(callback,
input,
boost::system::error_code(),
std::distance(new_start, data_end),
Expand All @@ -290,7 +291,7 @@ class async_server_connection

socket().async_read_some(
boost::asio::buffer(read_buffer_),
strand.wrap(boost::bind(&async_server_connection::wrap_read_handler,
strand.wrap(std::bind(&async_server_connection::wrap_read_handler,
async_server_connection::shared_from_this(),
callback,
boost::asio::placeholders::error,
Expand All @@ -315,7 +316,7 @@ class async_server_connection
data_end = read_buffer_.begin();
std::advance(data_end, bytes_transferred);
thread_pool()
.post(boost::bind(callback,
.post(std::bind(callback,
boost::make_iterator_range(data_start, data_end),
ec,
bytes_transferred,
Expand Down Expand Up @@ -371,7 +372,7 @@ class async_server_connection
void read_more(state_t state) {
socket_.async_read_some(
boost::asio::buffer(read_buffer_),
strand.wrap(boost::bind(&async_server_connection::handle_read_data,
strand.wrap(std::bind(&async_server_connection::handle_read_data,
async_server_connection::shared_from_this(),
state,
boost::asio::placeholders::error,
Expand Down Expand Up @@ -473,7 +474,7 @@ class async_server_connection
}
new_start = boost::end(result_range);
thread_pool()
.post(boost::bind(handler,
.post(std::bind(handler,
boost::cref(request_),
async_server_connection::shared_from_this()));
return;
Expand Down Expand Up @@ -502,7 +503,7 @@ class async_server_connection
boost::asio::async_write(
socket(),
boost::asio::buffer(bad_request, strlen(bad_request)),
strand.wrap(boost::bind(&async_server_connection::client_error_sent,
strand.wrap(std::bind(&async_server_connection::client_error_sent,
async_server_connection::shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
Expand All @@ -528,7 +529,7 @@ class async_server_connection
boost::asio::async_write(
socket(),
headers_buffer,
strand.wrap(boost::bind(&async_server_connection::handle_write_headers,
strand.wrap(std::bind(&async_server_connection::handle_write_headers,
async_server_connection::shared_from_this(),
callback,
boost::asio::placeholders::error,
Expand Down Expand Up @@ -561,7 +562,7 @@ class async_server_connection
boost::system::error_code const& ec,
std::size_t bytes_transferred) {
// we want to forget the temporaries and buffers
thread_pool().post(boost::bind(callback, ec));
thread_pool().post(std::bind(callback, ec));
}

template <class Range>
Expand Down Expand Up @@ -621,7 +622,7 @@ class async_server_connection
std::function<void(boost::system::error_code)> callback_function = callback;

std::function<void()> continuation =
boost::bind(
std::bind(
&async_server_connection::template write_vec_impl<
ConstBufferSeq,
std::function<void(
Expand All @@ -643,7 +644,7 @@ class async_server_connection
boost::asio::async_write(
socket_,
seq,
boost::bind(&async_server_connection::handle_write,
std::bind(&async_server_connection::handle_write,
async_server_connection::shared_from_this(),
callback_function,
temporaries,
Expand Down
12 changes: 6 additions & 6 deletions http/src/network/protocol/http/server/connection/sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <utility>
#include <iterator>
#include <boost/enable_shared_from_this.hpp>
// #include <boost/enable_shared_from_this.hpp>
#include <network/constants.hpp>
#include <network/protocol/http/server/request_parser.hpp>
#include <network/protocol/http/request.hpp>
Expand Down Expand Up @@ -43,7 +43,7 @@ extern void parse_headers(
#endif

class sync_server_connection
: public boost::enable_shared_from_this<sync_server_connection> {
: public std::enable_shared_from_this<sync_server_connection> {
public:
sync_server_connection(boost::asio::io_service& service,
std::function<void(request const&, response&)> handler)
Expand All @@ -64,7 +64,7 @@ class sync_server_connection
<< socket_.remote_endpoint().port();
request_.set_source(ip_stream.str());
socket_.async_read_some(boost::asio::buffer(read_buffer_),
wrapper_.wrap(boost::bind(
wrapper_.wrap(std::bind(
&sync_server_connection::handle_read_data,
sync_server_connection::shared_from_this(),
method,
Expand Down Expand Up @@ -196,7 +196,7 @@ class sync_server_connection
socket_,
response_buffers,
wrapper_.wrap(
boost::bind(&sync_server_connection::handle_write,
std::bind(&sync_server_connection::handle_write,
sync_server_connection::shared_from_this(),
boost::asio::placeholders::error)));
}
Expand Down Expand Up @@ -235,7 +235,7 @@ class sync_server_connection
socket(),
boost::asio::buffer(bad_request, strlen(bad_request)),
wrapper_.wrap(
boost::bind(&sync_server_connection::client_error_sent,
std::bind(&sync_server_connection::client_error_sent,
sync_server_connection::shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
Expand All @@ -254,7 +254,7 @@ class sync_server_connection

void read_more(state_t state) {
socket_.async_read_some(boost::asio::buffer(read_buffer_),
wrapper_.wrap(boost::bind(
wrapper_.wrap(std::bind(
&sync_server_connection::handle_read_data,
sync_server_connection::shared_from_this(),
state,
Expand Down
2 changes: 1 addition & 1 deletion http/test/server_async_less_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct async_hello_world {
connection->set_headers(boost::make_iterator_range(headers, headers + 4));
std::vector<boost::asio::const_buffer> iovec;
iovec.push_back(boost::asio::const_buffer(hello_world, 13));
connection->write(iovec, boost::bind(&async_hello_world::error, this, _1));
connection->write(iovec, std::bind(&async_hello_world::error, this, _1));
}

void error(boost::system::error_code const& ec) {
Expand Down
Loading