Skip to content

Fix for boost 1.70 (get_io_service() was deprecated and was removed) #878

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 6 commits into from
Aug 12, 2019
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
19 changes: 19 additions & 0 deletions boost/network/compat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef BOOST_NETWORK_COMPAT_HPP__
#define BOOST_NETWORK_COMPAT_HPP__

// Copyright 2019 (C) Enrico Detoma
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// These macros are used to solve a compatibility problem with Boost >= 1.70
// where the deprecated method get_io_service() was removed.
#if BOOST_VERSION >= 107000
#define CPP_NETLIB_ASIO_GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
#define CPP_NETLIB_ASIO_IO_SERVICE_CONTEXT boost::asio::io_context
#else
#define CPP_NETLIB_ASIO_GET_IO_SERVICE(s) ((s).get_io_service())
#define CPP_NETLIB_ASIO_IO_SERVICE_CONTEXT boost::asio::io_service
#endif

#endif // BOOST_NETWORK_COMPAT_HPP__
3 changes: 2 additions & 1 deletion boost/network/protocol/http/client/connection/async_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/network/protocol/http/client/connection/async_normal.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/network/traits/string.hpp>
#include <boost/network/compat.hpp>

namespace boost {
namespace network {
Expand Down Expand Up @@ -59,7 +60,7 @@ struct async_connection_base {
async_connection;
typedef typename delegate_factory<Tag>::type delegate_factory_type;
auto delegate = delegate_factory_type::new_connection_delegate(
resolver.get_io_service(), https, always_verify_peer,
CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver), https, always_verify_peer,
certificate_filename, verify_path, certificate_file, private_key_file,
ciphers, sni_hostname, ssl_options);
auto temp = std::make_shared<async_connection>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <boost/range/algorithm/transform.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/throw_exception.hpp>
#include <boost/network/compat.hpp>

namespace boost {
namespace network {
Expand Down Expand Up @@ -154,12 +155,12 @@ struct http_async_connection
connection_delegate_ptr delegate)
: timeout_(timeout),
remove_chunk_markers_(remove_chunk_markers),
timer_(resolver.get_io_service()),
timer_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver)),
is_timedout_(false),
follow_redirect_(follow_redirect),
resolver_(resolver),
resolve_(std::move(resolve)),
request_strand_(resolver.get_io_service()),
request_strand_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver)),
delegate_(std::move(delegate)) {}

// This is the main entry point for the connection/request pipeline.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct connection_delegate_factory {
// This is the factory method that actually returns the delegate instance.
// TODO(dberris): Support passing in proxy settings when crafting connections.
static connection_delegate_ptr new_connection_delegate(
boost::asio::io_service& service, bool https, bool always_verify_peer,
CPP_NETLIB_ASIO_IO_SERVICE_CONTEXT& service,
bool https, bool always_verify_peer,
optional<string_type> certificate_filename,
optional<string_type> verify_path, optional<string_type> certificate_file,
optional<string_type> private_key_file, optional<string_type> ciphers,
Expand Down
5 changes: 3 additions & 2 deletions boost/network/protocol/http/client/connection/sync_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/network/protocol/http/response.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/network/traits/string.hpp>
#include <boost/network/compat.hpp>

namespace boost {
namespace network {
Expand Down Expand Up @@ -49,10 +50,10 @@ struct http_sync_connection
int timeout)
: connection_base(),
timeout_(timeout),
timer_(resolver.get_io_service()),
timer_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver)),
resolver_(resolver),
resolve_(std::move(resolve)),
socket_(resolver.get_io_service()) {}
socket_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver)) {}

void init_socket(string_type const& hostname, string_type const& port) {
connection_base::init_socket(socket_, resolver_, hostname, port, resolve_);
Expand Down
7 changes: 4 additions & 3 deletions boost/network/protocol/http/client/connection/sync_ssl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/network/protocol/http/request.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/network/compat.hpp>

namespace boost {
namespace network {
Expand Down Expand Up @@ -60,11 +61,11 @@ struct https_sync_connection
long ssl_options = 0)
: connection_base(),
timeout_(timeout),
timer_(resolver.get_io_service()),
timer_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver)),
resolver_(resolver),
resolve_(std::move(resolve)),
context_(resolver.get_io_service(), boost::asio::ssl::context::sslv23_client),
socket_(resolver.get_io_service(), context_) {
context_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver), boost::asio::ssl::context::sslv23_client),
socket_(CPP_NETLIB_ASIO_GET_IO_SERVICE(resolver), context_) {
if (ciphers) {
::SSL_CTX_set_cipher_list(context_.native_handle(), ciphers->c_str());
}
Expand Down