mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Support Boost 1.70:
This patch removes calls to several deprecated asio functions. * `io_service::post` becomes `post` (free function) * `io_service::work` becomes `executor_work_guard` * `io_service::wrap` becomes `bind_executor` * `get_io_context` becomes `get_executor` or `get_executor().context()` This patch was tested with boost 1.69 and 1.70. The functions `ripple::get_lowest_layer` and `beast::create_waitable_timer` are required to handle a breaking difference between these versions. When rippled no longer needs to support pre 1.70 boost versions, both of these functions may be removed, and the waitable timer injections may also be removed.
This commit is contained in:
@@ -58,14 +58,14 @@ public:
|
||||
};
|
||||
|
||||
TrustedPublisherServer(
|
||||
boost::asio::io_service& ios,
|
||||
boost::asio::io_context& ioc,
|
||||
std::pair<PublicKey, SecretKey> keys,
|
||||
std::string const& manifest,
|
||||
int sequence,
|
||||
NetClock::time_point expiration,
|
||||
int version,
|
||||
std::vector<Validator> const& validators)
|
||||
: sock_(ios), acceptor_(ios)
|
||||
: sock_(ioc), acceptor_(ioc)
|
||||
{
|
||||
endpoint_type const& ep {
|
||||
beast::IP::Address::from_string (ripple::test::getEnvLocalhostAddr()),
|
||||
@@ -124,13 +124,13 @@ private:
|
||||
int id;
|
||||
TrustedPublisherServer& self;
|
||||
socket_type sock;
|
||||
boost::asio::io_service::work work;
|
||||
boost::asio::executor_work_guard<boost::asio::executor> work;
|
||||
|
||||
lambda(int id_, TrustedPublisherServer& self_, socket_type&& sock_)
|
||||
: id(id_)
|
||||
, self(self_)
|
||||
, sock(std::move(sock_))
|
||||
, work(sock.get_io_service())
|
||||
, work(sock_.get_executor())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@ will complete with eof.
|
||||
class short_read_test : public beast::unit_test::suite
|
||||
{
|
||||
private:
|
||||
using io_service_type = boost::asio::io_service;
|
||||
using strand_type = io_service_type::strand;
|
||||
using io_context_type = boost::asio::io_context;
|
||||
using strand_type = boost::asio::io_context::strand;
|
||||
using timer_type = boost::asio::basic_waitable_timer<
|
||||
std::chrono::steady_clock>;
|
||||
using acceptor_type = boost::asio::ip::tcp::acceptor;
|
||||
@@ -59,8 +59,8 @@ private:
|
||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||
using address_type = boost::asio::ip::address;
|
||||
|
||||
io_service_type io_service_;
|
||||
boost::optional<io_service_type::work> work_;
|
||||
io_context_type io_context_;
|
||||
boost::optional<boost::asio::executor_work_guard<boost::asio::executor>> work_;
|
||||
std::thread thread_;
|
||||
std::shared_ptr<boost::asio::ssl::context> context_;
|
||||
|
||||
@@ -183,11 +183,11 @@ private:
|
||||
: Child(server)
|
||||
, server_(server)
|
||||
, test_(server_.test_)
|
||||
, acceptor_(test_.io_service_,
|
||||
, acceptor_(test_.io_context_,
|
||||
endpoint_type(beast::IP::Address::from_string(
|
||||
test::getEnvLocalhostAddr()), 0))
|
||||
, socket_(test_.io_service_)
|
||||
, strand_(socket_.get_io_service())
|
||||
, socket_(test_.io_context_)
|
||||
, strand_(test_.io_context_)
|
||||
{
|
||||
acceptor_.listen();
|
||||
server_.endpoint_ = acceptor_.local_endpoint();
|
||||
@@ -199,7 +199,7 @@ private:
|
||||
close() override
|
||||
{
|
||||
if(! strand_.running_in_this_thread())
|
||||
return strand_.post(std::bind(&Acceptor::close,
|
||||
return post(strand_, std::bind(&Acceptor::close,
|
||||
shared_from_this()));
|
||||
acceptor_.close();
|
||||
}
|
||||
@@ -207,9 +207,14 @@ private:
|
||||
void
|
||||
run()
|
||||
{
|
||||
acceptor_.async_accept(socket_, strand_.wrap(std::bind(
|
||||
&Acceptor::on_accept, shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Acceptor::on_accept,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -233,9 +238,14 @@ private:
|
||||
server_, std::move(socket_));
|
||||
server_.add(p);
|
||||
p->run();
|
||||
acceptor_.async_accept(socket_, strand_.wrap(std::bind(
|
||||
&Acceptor::on_accept, shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Acceptor::on_accept,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -256,8 +266,8 @@ private:
|
||||
, test_(server_.test_)
|
||||
, socket_(std::move(socket))
|
||||
, stream_(socket_, *test_.context_)
|
||||
, strand_(socket_.get_io_service())
|
||||
, timer_(socket_.get_io_service())
|
||||
, strand_(test_.io_context_)
|
||||
, timer_(test_.io_context_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -265,7 +275,7 @@ private:
|
||||
close() override
|
||||
{
|
||||
if(! strand_.running_in_this_thread())
|
||||
return strand_.post(std::bind(&Connection::close,
|
||||
return post(strand_, std::bind(&Connection::close,
|
||||
shared_from_this()));
|
||||
if (socket_.is_open())
|
||||
{
|
||||
@@ -278,11 +288,20 @@ private:
|
||||
run()
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer,
|
||||
shared_from_this(), std::placeholders::_1)));
|
||||
stream_.async_handshake(stream_type::server, strand_.wrap(
|
||||
std::bind(&Connection::on_handshake, shared_from_this(),
|
||||
timer_.async_wait(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_timer,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
stream_.async_handshake(
|
||||
stream_type::server,
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_handshake,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -315,9 +334,16 @@ private:
|
||||
if (ec)
|
||||
return fail("handshake", ec);
|
||||
#if 1
|
||||
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap(
|
||||
std::bind(&Connection::on_read, shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
boost::asio::async_read_until(
|
||||
stream_,
|
||||
buf_,
|
||||
"\n",
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_read,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
close();
|
||||
@@ -330,8 +356,11 @@ private:
|
||||
if (ec == boost::asio::error::eof)
|
||||
{
|
||||
server_.test_.log << "[server] read: EOF" << std::endl;
|
||||
return stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
return stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_shutdown,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
if (ec)
|
||||
@@ -340,9 +369,15 @@ private:
|
||||
buf_.commit(bytes_transferred);
|
||||
buf_.consume(bytes_transferred);
|
||||
write(buf_, "BYE\n");
|
||||
boost::asio::async_write(stream_, buf_.data(), strand_.wrap(
|
||||
std::bind(&Connection::on_write, shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
boost::asio::async_write(
|
||||
stream_,
|
||||
buf_.data(),
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_write,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
}
|
||||
|
||||
@@ -352,8 +387,11 @@ private:
|
||||
buf_.consume(bytes_transferred);
|
||||
if (ec)
|
||||
return fail("write", ec);
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_shutdown,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
@@ -412,10 +450,10 @@ private:
|
||||
: Child(client)
|
||||
, client_(client)
|
||||
, test_(client_.test_)
|
||||
, socket_(test_.io_service_)
|
||||
, socket_(test_.io_context_)
|
||||
, stream_(socket_, *test_.context_)
|
||||
, strand_(socket_.get_io_service())
|
||||
, timer_(socket_.get_io_service())
|
||||
, strand_(test_.io_context_)
|
||||
, timer_(test_.io_context_)
|
||||
, ep_(ep)
|
||||
{
|
||||
}
|
||||
@@ -424,8 +462,9 @@ private:
|
||||
close() override
|
||||
{
|
||||
if(! strand_.running_in_this_thread())
|
||||
return strand_.post(std::bind(&Connection::close,
|
||||
shared_from_this()));
|
||||
return post(
|
||||
strand_,
|
||||
std::bind(&Connection::close, shared_from_this()));
|
||||
if (socket_.is_open())
|
||||
{
|
||||
socket_.close();
|
||||
@@ -437,11 +476,20 @@ private:
|
||||
run(endpoint_type const& ep)
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer,
|
||||
shared_from_this(), std::placeholders::_1)));
|
||||
socket_.async_connect(ep, strand_.wrap(std::bind(
|
||||
&Connection::on_connect, shared_from_this(),
|
||||
timer_.async_wait(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_timer,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
socket_.async_connect(
|
||||
ep,
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_connect,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -473,9 +521,14 @@ private:
|
||||
{
|
||||
if (ec)
|
||||
return fail("connect", ec);
|
||||
stream_.async_handshake(stream_type::client, strand_.wrap(
|
||||
std::bind(&Connection::on_handshake, shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
stream_.async_handshake(
|
||||
stream_type::client,
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_handshake,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -486,13 +539,22 @@ private:
|
||||
write(buf_, "HELLO\n");
|
||||
|
||||
#if 1
|
||||
boost::asio::async_write(stream_, buf_.data(), strand_.wrap(
|
||||
std::bind(&Connection::on_write, shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
boost::asio::async_write(
|
||||
stream_,
|
||||
buf_.data(),
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_write,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_shutdown,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
#endif
|
||||
}
|
||||
@@ -504,13 +566,23 @@ private:
|
||||
if (ec)
|
||||
return fail("write", ec);
|
||||
#if 1
|
||||
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap(
|
||||
std::bind(&Connection::on_read, shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
boost::asio::async_read_until(
|
||||
stream_,
|
||||
buf_,
|
||||
"\n",
|
||||
bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_read,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_shutdown,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
#endif
|
||||
}
|
||||
@@ -521,8 +593,11 @@ private:
|
||||
if (ec)
|
||||
return fail("read", ec);
|
||||
buf_.commit(bytes_transferred);
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
stream_.async_shutdown(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&Connection::on_shutdown,
|
||||
shared_from_this(),
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
@@ -555,12 +630,11 @@ private:
|
||||
|
||||
public:
|
||||
short_read_test()
|
||||
: work_(boost::in_place(std::ref(io_service_)))
|
||||
, thread_(std::thread([this]()
|
||||
{
|
||||
beast::setCurrentThreadName("io_service");
|
||||
this->io_service_.run();
|
||||
}))
|
||||
: work_(io_context_.get_executor())
|
||||
, thread_(std::thread([this]() {
|
||||
beast::setCurrentThreadName("io_context");
|
||||
this->io_context_.run();
|
||||
}))
|
||||
, context_(make_SSLContext(""))
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user