mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
refactor: Update to Boost 1.88 (#5570)
This updates Boost to 1.88, which is needed because Clio wants to move to 1.88 as that fixes several ASAN false positives around coroutine usage. In order for Clio to move to newer boost, libXRPL needs to move too. Hence the changes in this PR. A lot has changed between 1.83 and 1.88 so there are lots of changes in the diff, especially in regards to Boost.Asio and coroutines in particular.
This commit is contained in:
@@ -63,7 +63,7 @@ public:
|
||||
pUrl_.domain,
|
||||
pUrl_.path,
|
||||
port_,
|
||||
env_.app().getIOService(),
|
||||
env_.app().getIOContext(),
|
||||
env_.journal,
|
||||
env_.app().config(),
|
||||
lastEndpoint,
|
||||
@@ -80,10 +80,11 @@ public:
|
||||
isMultipleEndpoints()
|
||||
{
|
||||
using boost::asio::ip::tcp;
|
||||
tcp::resolver resolver(env_.app().getIOService());
|
||||
tcp::resolver resolver(env_.app().getIOContext());
|
||||
std::string port = pUrl_.port ? std::to_string(*pUrl_.port) : "443";
|
||||
tcp::resolver::iterator it = resolver.resolve(pUrl_.domain, port);
|
||||
tcp::resolver::iterator end;
|
||||
auto results = resolver.resolve(pUrl_.domain, port);
|
||||
auto it = results.begin();
|
||||
auto end = results.end();
|
||||
int n = 0;
|
||||
for (; it != end; ++it)
|
||||
++n;
|
||||
|
||||
@@ -1107,7 +1107,7 @@ struct LedgerReplayer_test : public beast::unit_test::suite
|
||||
return false;
|
||||
|
||||
beast::IP::Address addr =
|
||||
boost::asio::ip::address::from_string("172.1.1.100");
|
||||
boost::asio::ip::make_address("172.1.1.100");
|
||||
jtx::Env serverEnv(*this);
|
||||
serverEnv.app().config().LEDGER_REPLAY = server;
|
||||
auto http_resp = ripple::makeResponse(
|
||||
|
||||
@@ -205,7 +205,7 @@ private:
|
||||
NetClock::time_point const expires2 =
|
||||
effective2 + cfg.expiresFromNow;
|
||||
item.server = make_TrustedPublisherServer(
|
||||
env.app().getIOService(),
|
||||
env.app().getIOContext(),
|
||||
item.list,
|
||||
expires,
|
||||
{{effective2, expires2}},
|
||||
|
||||
@@ -45,13 +45,13 @@ public:
|
||||
std::string const& normal = "")
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
Address const result{Address::from_string(s, ec)};
|
||||
Address const result{boost::asio::ip::make_address(s, ec)};
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
if (!BEAST_EXPECTS(result.is_v4(), s + " not v4"))
|
||||
return;
|
||||
if (!BEAST_EXPECTS(
|
||||
result.to_v4().to_ulong() == value, s + " value mismatch"))
|
||||
result.to_v4().to_uint() == value, s + " value mismatch"))
|
||||
return;
|
||||
BEAST_EXPECTS(
|
||||
result.to_string() == (normal.empty() ? s : normal),
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
failParseAddr(std::string const& s)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
auto a = Address::from_string(s, ec);
|
||||
auto a = boost::asio::ip::make_address(s, ec);
|
||||
BEAST_EXPECTS(ec, s + " parses as " + a.to_string());
|
||||
}
|
||||
|
||||
@@ -71,24 +71,24 @@ public:
|
||||
{
|
||||
testcase("AddressV4");
|
||||
|
||||
BEAST_EXPECT(AddressV4{}.to_ulong() == 0);
|
||||
BEAST_EXPECT(AddressV4{}.to_uint() == 0);
|
||||
BEAST_EXPECT(is_unspecified(AddressV4{}));
|
||||
BEAST_EXPECT(AddressV4{0x01020304}.to_ulong() == 0x01020304);
|
||||
BEAST_EXPECT(AddressV4{0x01020304}.to_uint() == 0x01020304);
|
||||
|
||||
{
|
||||
AddressV4::bytes_type d = {{1, 2, 3, 4}};
|
||||
BEAST_EXPECT(AddressV4{d}.to_ulong() == 0x01020304);
|
||||
BEAST_EXPECT(AddressV4{d}.to_uint() == 0x01020304);
|
||||
|
||||
unexpected(is_unspecified(AddressV4{d}));
|
||||
}
|
||||
|
||||
AddressV4 const v1{1};
|
||||
BEAST_EXPECT(AddressV4{v1}.to_ulong() == 1);
|
||||
BEAST_EXPECT(AddressV4{v1}.to_uint() == 1);
|
||||
|
||||
{
|
||||
AddressV4 v;
|
||||
v = v1;
|
||||
BEAST_EXPECT(v.to_ulong() == v1.to_ulong());
|
||||
BEAST_EXPECT(v.to_uint() == v1.to_uint());
|
||||
}
|
||||
|
||||
{
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
d[2] = 3;
|
||||
d[3] = 4;
|
||||
v = AddressV4{d};
|
||||
BEAST_EXPECT(v.to_ulong() == 0x01020304);
|
||||
BEAST_EXPECT(v.to_uint() == 0x01020304);
|
||||
}
|
||||
|
||||
BEAST_EXPECT(AddressV4(0x01020304).to_string() == "1.2.3.4");
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
testcase("Address");
|
||||
|
||||
boost::system::error_code ec;
|
||||
Address result{Address::from_string("1.2.3.4", ec)};
|
||||
Address result{boost::asio::ip::make_address("1.2.3.4", ec)};
|
||||
AddressV4::bytes_type d = {{1, 2, 3, 4}};
|
||||
BEAST_EXPECT(!ec);
|
||||
BEAST_EXPECT(result.is_v4() && result.to_v4() == AddressV4{d});
|
||||
@@ -263,7 +263,10 @@ public:
|
||||
BEAST_EXPECT(is_loopback(ep));
|
||||
BEAST_EXPECT(to_string(ep) == "127.0.0.1:80");
|
||||
// same address as v4 mapped in ipv6
|
||||
ep = Endpoint(AddressV6::v4_mapped(AddressV4{d}), 80);
|
||||
ep = Endpoint(
|
||||
boost::asio::ip::make_address_v6(
|
||||
boost::asio::ip::v4_mapped, AddressV4{d}),
|
||||
80);
|
||||
BEAST_EXPECT(!is_unspecified(ep));
|
||||
BEAST_EXPECT(!is_public(ep));
|
||||
BEAST_EXPECT(is_private(ep));
|
||||
@@ -281,8 +284,11 @@ public:
|
||||
BEAST_EXPECT(!is_loopback(ep));
|
||||
BEAST_EXPECT(to_string(ep) == "10.0.0.1");
|
||||
// same address as v4 mapped in ipv6
|
||||
ep = Endpoint(AddressV6::v4_mapped(AddressV4{d}));
|
||||
BEAST_EXPECT(get_class(ep.to_v6().to_v4()) == 'A');
|
||||
ep = Endpoint(boost::asio::ip::make_address_v6(
|
||||
boost::asio::ip::v4_mapped, AddressV4{d}));
|
||||
BEAST_EXPECT(
|
||||
get_class(boost::asio::ip::make_address_v4(
|
||||
boost::asio::ip::v4_mapped, ep.to_v6())) == 'A');
|
||||
BEAST_EXPECT(!is_unspecified(ep));
|
||||
BEAST_EXPECT(!is_public(ep));
|
||||
BEAST_EXPECT(is_private(ep));
|
||||
@@ -299,7 +305,8 @@ public:
|
||||
BEAST_EXPECT(!is_loopback(ep));
|
||||
BEAST_EXPECT(to_string(ep) == "166.78.151.147");
|
||||
// same address as v4 mapped in ipv6
|
||||
ep = Endpoint(AddressV6::v4_mapped(AddressV4{d}));
|
||||
ep = Endpoint(boost::asio::ip::make_address_v6(
|
||||
boost::asio::ip::v4_mapped, AddressV4{d}));
|
||||
BEAST_EXPECT(!is_unspecified(ep));
|
||||
BEAST_EXPECT(is_public(ep));
|
||||
BEAST_EXPECT(!is_private(ep));
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
@@ -60,8 +61,10 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
measure_asio_timers(duration interval = 100ms, size_t num_samples = 50)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
boost::asio::io_service ios;
|
||||
std::optional<boost::asio::io_service::work> work{ios};
|
||||
boost::asio::io_context ios;
|
||||
std::optional<boost::asio::executor_work_guard<
|
||||
boost::asio::io_context::executor_type>>
|
||||
work{boost::asio::make_work_guard(ios)};
|
||||
std::thread worker{[&] { ios.run(); }};
|
||||
boost::asio::basic_waitable_timer<Clock> timer{ios};
|
||||
elapsed_times_.reserve(num_samples);
|
||||
@@ -135,7 +138,7 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
|
||||
test_sampler(
|
||||
std::chrono::milliseconds interval,
|
||||
boost::asio::io_service& ios)
|
||||
boost::asio::io_context& ios)
|
||||
: probe_(interval, ios)
|
||||
{
|
||||
}
|
||||
@@ -164,9 +167,9 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
{
|
||||
testcase << "sample one";
|
||||
boost::system::error_code ec;
|
||||
test_sampler io_probe{100ms, get_io_service()};
|
||||
test_sampler io_probe{100ms, get_io_context()};
|
||||
io_probe.start_one();
|
||||
MyTimer timer{get_io_service(), 1s};
|
||||
MyTimer timer{get_io_context(), 1s};
|
||||
timer.async_wait(yield[ec]);
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
@@ -198,9 +201,9 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
duration_cast<milliseconds>(probe_duration).count()) /
|
||||
static_cast<size_t>(tt.getMean<milliseconds>());
|
||||
#endif
|
||||
test_sampler io_probe{interval, get_io_service()};
|
||||
test_sampler io_probe{interval, get_io_context()};
|
||||
io_probe.start();
|
||||
MyTimer timer{get_io_service(), probe_duration};
|
||||
MyTimer timer{get_io_context(), probe_duration};
|
||||
timer.async_wait(yield[ec]);
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
@@ -212,7 +215,7 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
io_probe.probe_.cancel_async();
|
||||
// wait again in order to flush the remaining
|
||||
// probes from the work queue
|
||||
timer.expires_from_now(1s);
|
||||
timer.expires_after(1s);
|
||||
timer.async_wait(yield[ec]);
|
||||
}
|
||||
|
||||
@@ -220,7 +223,7 @@ class io_latency_probe_test : public beast::unit_test::suite,
|
||||
testCanceled(boost::asio::yield_context& yield)
|
||||
{
|
||||
testcase << "canceled";
|
||||
test_sampler io_probe{100ms, get_io_service()};
|
||||
test_sampler io_probe{100ms, get_io_context()};
|
||||
io_probe.probe_.cancel_async();
|
||||
except<std::logic_error>([&io_probe]() { io_probe.start_one(); });
|
||||
except<std::logic_error>([&io_probe]() { io_probe.start(); });
|
||||
|
||||
@@ -183,7 +183,7 @@ public:
|
||||
bool immediateStart = true,
|
||||
int sequence = 1)
|
||||
: sock_{ioc}
|
||||
, ep_{beast::IP::Address::from_string(
|
||||
, ep_{boost::asio::ip::make_address(
|
||||
ripple::test::getEnvLocalhostAddr()),
|
||||
// 0 means let OS pick the port based on what's available
|
||||
0}
|
||||
@@ -284,7 +284,7 @@ public:
|
||||
acceptor_.set_option(
|
||||
boost::asio::ip::tcp::acceptor::reuse_address(true), ec);
|
||||
acceptor_.bind(ep_);
|
||||
acceptor_.listen(boost::asio::socket_base::max_connections);
|
||||
acceptor_.listen(boost::asio::socket_base::max_listen_connections);
|
||||
acceptor_.async_accept(
|
||||
sock_,
|
||||
[wp = std::weak_ptr<TrustedPublisherServer>{shared_from_this()}](
|
||||
|
||||
@@ -78,7 +78,7 @@ class JSONRPCClient : public AbstractClient
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::endpoint ep_;
|
||||
boost::asio::io_service ios_;
|
||||
boost::asio::io_context ios_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
boost::beast::multi_buffer bin_;
|
||||
boost::beast::multi_buffer bout_;
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#include <xrpl/protocol/jss.h>
|
||||
#include <xrpl/server/Port.h>
|
||||
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
|
||||
@@ -89,9 +92,11 @@ class WSClientImpl : public WSClient
|
||||
return s;
|
||||
}
|
||||
|
||||
boost::asio::io_service ios_;
|
||||
std::optional<boost::asio::io_service::work> work_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
boost::asio::io_context ios_;
|
||||
std::optional<boost::asio::executor_work_guard<
|
||||
boost::asio::io_context::executor_type>>
|
||||
work_;
|
||||
boost::asio::strand<boost::asio::io_context::executor_type> strand_;
|
||||
std::thread thread_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
boost::beast::websocket::stream<boost::asio::ip::tcp::socket&> ws_;
|
||||
@@ -114,14 +119,24 @@ class WSClientImpl : public WSClient
|
||||
void
|
||||
cleanup()
|
||||
{
|
||||
ios_.post(strand_.wrap([this] {
|
||||
if (!peerClosed_)
|
||||
{
|
||||
ws_.async_close({}, strand_.wrap([&](error_code ec) {
|
||||
stream_.cancel(ec);
|
||||
}));
|
||||
}
|
||||
}));
|
||||
boost::asio::post(
|
||||
ios_, boost::asio::bind_executor(strand_, [this] {
|
||||
if (!peerClosed_)
|
||||
{
|
||||
ws_.async_close(
|
||||
{},
|
||||
boost::asio::bind_executor(strand_, [&](error_code) {
|
||||
try
|
||||
{
|
||||
stream_.cancel();
|
||||
}
|
||||
catch (boost::system::system_error const&)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}));
|
||||
}
|
||||
}));
|
||||
work_ = std::nullopt;
|
||||
thread_.join();
|
||||
}
|
||||
@@ -132,8 +147,8 @@ public:
|
||||
bool v2,
|
||||
unsigned rpc_version,
|
||||
std::unordered_map<std::string, std::string> const& headers = {})
|
||||
: work_(ios_)
|
||||
, strand_(ios_)
|
||||
: work_(std::in_place, boost::asio::make_work_guard(ios_))
|
||||
, strand_(boost::asio::make_strand(ios_))
|
||||
, thread_([&] { ios_.run(); })
|
||||
, stream_(ios_)
|
||||
, ws_(stream_)
|
||||
@@ -153,8 +168,12 @@ public:
|
||||
"/");
|
||||
ws_.async_read(
|
||||
rb_,
|
||||
strand_.wrap(std::bind(
|
||||
&WSClientImpl::on_read_msg, this, std::placeholders::_1)));
|
||||
boost::asio::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&WSClientImpl::on_read_msg,
|
||||
this,
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
@@ -284,8 +303,10 @@ private:
|
||||
}
|
||||
ws_.async_read(
|
||||
rb_,
|
||||
strand_.wrap(std::bind(
|
||||
&WSClientImpl::on_read_msg, this, std::placeholders::_1)));
|
||||
boost::asio::bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
&WSClientImpl::on_read_msg, this, std::placeholders::_1)));
|
||||
}
|
||||
|
||||
// Called when the read op terminates
|
||||
|
||||
@@ -485,7 +485,7 @@ public:
|
||||
};
|
||||
auto handshake = [&](int outboundEnable, int inboundEnable) {
|
||||
beast::IP::Address addr =
|
||||
boost::asio::ip::address::from_string("172.1.1.100");
|
||||
boost::asio::ip::make_address("172.1.1.100");
|
||||
|
||||
auto env = getEnv(outboundEnable);
|
||||
auto request = ripple::makeRequest(
|
||||
|
||||
@@ -1655,7 +1655,7 @@ vp_base_squelch_max_selected_peers=2
|
||||
};
|
||||
auto handshake = [&](int outboundEnable, int inboundEnable) {
|
||||
beast::IP::Address addr =
|
||||
boost::asio::ip::address::from_string("172.1.1.100");
|
||||
boost::asio::ip::make_address("172.1.1.100");
|
||||
|
||||
setEnv(outboundEnable);
|
||||
auto request = ripple::makeRequest(
|
||||
|
||||
@@ -23,12 +23,17 @@
|
||||
#include <xrpl/beast/core/CurrentThreadName.h>
|
||||
#include <xrpl/beast/unit_test.h>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/bind_executor.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/read_until.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
@@ -49,7 +54,7 @@ class short_read_test : public beast::unit_test::suite
|
||||
{
|
||||
private:
|
||||
using io_context_type = boost::asio::io_context;
|
||||
using strand_type = boost::asio::io_context::strand;
|
||||
using strand_type = boost::asio::strand<io_context_type::executor_type>;
|
||||
using timer_type =
|
||||
boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
|
||||
using acceptor_type = boost::asio::ip::tcp::acceptor;
|
||||
@@ -60,7 +65,8 @@ private:
|
||||
using address_type = boost::asio::ip::address;
|
||||
|
||||
io_context_type io_context_;
|
||||
std::optional<boost::asio::executor_work_guard<boost::asio::executor>>
|
||||
boost::optional<boost::asio::executor_work_guard<
|
||||
boost::asio::io_context::executor_type>>
|
||||
work_;
|
||||
std::thread thread_;
|
||||
std::shared_ptr<boost::asio::ssl::context> context_;
|
||||
@@ -72,7 +78,7 @@ private:
|
||||
using boost::asio::buffer;
|
||||
using boost::asio::buffer_copy;
|
||||
using boost::asio::buffer_size;
|
||||
boost::asio::const_buffers_1 buf(s.data(), s.size());
|
||||
boost::asio::const_buffer buf(s.data(), s.size());
|
||||
sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
|
||||
}
|
||||
|
||||
@@ -185,11 +191,11 @@ private:
|
||||
, acceptor_(
|
||||
test_.io_context_,
|
||||
endpoint_type(
|
||||
beast::IP::Address::from_string(
|
||||
boost::asio::ip::make_address(
|
||||
test::getEnvLocalhostAddr()),
|
||||
0))
|
||||
, socket_(test_.io_context_)
|
||||
, strand_(test_.io_context_)
|
||||
, strand_(boost::asio::make_strand(test_.io_context_))
|
||||
{
|
||||
acceptor_.listen();
|
||||
server_.endpoint_ = acceptor_.local_endpoint();
|
||||
@@ -265,7 +271,7 @@ private:
|
||||
, test_(server_.test_)
|
||||
, socket_(std::move(socket))
|
||||
, stream_(socket_, *test_.context_)
|
||||
, strand_(test_.io_context_)
|
||||
, strand_(boost::asio::make_strand(test_.io_context_))
|
||||
, timer_(test_.io_context_)
|
||||
{
|
||||
}
|
||||
@@ -287,7 +293,7 @@ private:
|
||||
void
|
||||
run()
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.expires_after(std::chrono::seconds(3));
|
||||
timer_.async_wait(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
@@ -450,7 +456,7 @@ private:
|
||||
, test_(client_.test_)
|
||||
, socket_(test_.io_context_)
|
||||
, stream_(socket_, *test_.context_)
|
||||
, strand_(test_.io_context_)
|
||||
, strand_(boost::asio::make_strand(test_.io_context_))
|
||||
, timer_(test_.io_context_)
|
||||
, ep_(ep)
|
||||
{
|
||||
@@ -473,7 +479,7 @@ private:
|
||||
void
|
||||
run(endpoint_type const& ep)
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.expires_after(std::chrono::seconds(3));
|
||||
timer_.async_wait(bind_executor(
|
||||
strand_,
|
||||
std::bind(
|
||||
|
||||
@@ -174,13 +174,13 @@ private:
|
||||
makeFeaturesRequestHeader(false, false, true, false))
|
||||
: (void)nDisabled--;
|
||||
auto stream_ptr = std::make_unique<stream_type>(
|
||||
socket_type(std::forward<boost::asio::io_service&>(
|
||||
env.app().getIOService())),
|
||||
socket_type(std::forward<boost::asio::io_context&>(
|
||||
env.app().getIOContext())),
|
||||
*context_);
|
||||
beast::IP::Endpoint local(
|
||||
beast::IP::Address::from_string("172.1.1." + std::to_string(lid_)));
|
||||
boost::asio::ip::make_address("172.1.1." + std::to_string(lid_)));
|
||||
beast::IP::Endpoint remote(
|
||||
beast::IP::Address::from_string("172.1.1." + std::to_string(rid_)));
|
||||
boost::asio::ip::make_address("172.1.1." + std::to_string(rid_)));
|
||||
PublicKey key(std::get<0>(randomKeyPair(KeyType::ed25519)));
|
||||
auto consumer = overlay.resourceManager().newInboundEndpoint(remote);
|
||||
auto slot = overlay.peerFinder().new_inbound_slot(local, remote);
|
||||
|
||||
@@ -187,14 +187,14 @@ public:
|
||||
for (auto const& val : validators)
|
||||
expectedKeys.insert(toStr(val.masterPublic));
|
||||
|
||||
// Manage single-thread io_service for server.
|
||||
// Manage single-thread io_context for server.
|
||||
BasicApp worker{1};
|
||||
using namespace std::chrono_literals;
|
||||
NetClock::time_point const validUntil{3600s};
|
||||
NetClock::time_point const validFrom2{validUntil - 60s};
|
||||
NetClock::time_point const validUntil2{validFrom2 + 3600s};
|
||||
auto server = make_TrustedPublisherServer(
|
||||
worker.get_io_service(),
|
||||
worker.get_io_context(),
|
||||
validators,
|
||||
validUntil,
|
||||
{{validFrom2, validUntil2}},
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
#include <boost/beast/http.hpp>
|
||||
@@ -165,12 +166,11 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
{
|
||||
using namespace boost::asio;
|
||||
using namespace boost::beast::http;
|
||||
io_service& ios = get_io_service();
|
||||
io_context& ios = get_io_context();
|
||||
ip::tcp::resolver r{ios};
|
||||
boost::beast::multi_buffer sb;
|
||||
|
||||
auto it = r.async_resolve(
|
||||
ip::tcp::resolver::query{host, std::to_string(port)}, yield[ec]);
|
||||
auto it = r.async_resolve(host, std::to_string(port), yield[ec]);
|
||||
if (ec)
|
||||
return;
|
||||
|
||||
@@ -476,12 +476,11 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
auto req_string = boost::lexical_cast<std::string>(req);
|
||||
req_string.erase(req_string.find_last_of("13"), std::string::npos);
|
||||
|
||||
io_service& ios = get_io_service();
|
||||
io_context& ios = get_io_context();
|
||||
ip::tcp::resolver r{ios};
|
||||
boost::beast::multi_buffer sb;
|
||||
|
||||
auto it = r.async_resolve(
|
||||
ip::tcp::resolver::query{*ip, std::to_string(*port)}, yield[ec]);
|
||||
auto it = r.async_resolve(*ip, std::to_string(*port), yield[ec]);
|
||||
if (!BEAST_EXPECTS(!ec, ec.message()))
|
||||
return;
|
||||
|
||||
@@ -610,14 +609,13 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
env.app().config()["port_rpc"].get<std::string>("ip").value();
|
||||
|
||||
boost::system::error_code ec;
|
||||
io_service& ios = get_io_service();
|
||||
io_context& ios = get_io_context();
|
||||
ip::tcp::resolver r{ios};
|
||||
|
||||
Json::Value jr;
|
||||
jr[jss::method] = "server_info";
|
||||
|
||||
auto it = r.async_resolve(
|
||||
ip::tcp::resolver::query{ip, std::to_string(port)}, yield[ec]);
|
||||
auto it = r.async_resolve(ip, std::to_string(port), yield[ec]);
|
||||
BEAST_EXPECT(!ec);
|
||||
|
||||
std::vector<std::pair<ip::tcp::socket, boost::beast::multi_buffer>>
|
||||
@@ -681,7 +679,7 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
resp["Upgrade"] == "websocket");
|
||||
BEAST_EXPECT(
|
||||
resp.find("Connection") != resp.end() &&
|
||||
resp["Connection"] == "Upgrade");
|
||||
boost::iequals(resp["Connection"], "upgrade"));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -728,11 +726,10 @@ class ServerStatus_test : public beast::unit_test::suite,
|
||||
env.app().config()["port_ws"].get<std::string>("ip").value();
|
||||
boost::system::error_code ec;
|
||||
|
||||
io_service& ios = get_io_service();
|
||||
io_context& ios = get_io_context();
|
||||
ip::tcp::resolver r{ios};
|
||||
|
||||
auto it = r.async_resolve(
|
||||
ip::tcp::resolver::query{ip, std::to_string(port)}, yield[ec]);
|
||||
auto it = r.async_resolve(ip, std::to_string(port), yield[ec]);
|
||||
if (!BEAST_EXPECT(!ec))
|
||||
return;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <xrpl/server/Session.h>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
#include <boost/beast/core/tcp_stream.hpp>
|
||||
#include <boost/beast/ssl/ssl_stream.hpp>
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
@@ -52,14 +53,16 @@ public:
|
||||
class TestThread
|
||||
{
|
||||
private:
|
||||
boost::asio::io_service io_service_;
|
||||
std::optional<boost::asio::io_service::work> work_;
|
||||
boost::asio::io_context io_context_;
|
||||
std::optional<boost::asio::executor_work_guard<
|
||||
boost::asio::io_context::executor_type>>
|
||||
work_;
|
||||
std::thread thread_;
|
||||
|
||||
public:
|
||||
TestThread()
|
||||
: work_(std::in_place, std::ref(io_service_))
|
||||
, thread_([&]() { this->io_service_.run(); })
|
||||
: work_(std::in_place, boost::asio::make_work_guard(io_context_))
|
||||
, thread_([&]() { this->io_context_.run(); })
|
||||
{
|
||||
}
|
||||
|
||||
@@ -69,10 +72,10 @@ public:
|
||||
thread_.join();
|
||||
}
|
||||
|
||||
boost::asio::io_service&
|
||||
get_io_service()
|
||||
boost::asio::io_context&
|
||||
get_io_context()
|
||||
{
|
||||
return io_service_;
|
||||
return io_context_;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -234,7 +237,7 @@ public:
|
||||
void
|
||||
test_request(boost::asio::ip::tcp::endpoint const& ep)
|
||||
{
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_context ios;
|
||||
using socket = boost::asio::ip::tcp::socket;
|
||||
socket s(ios);
|
||||
|
||||
@@ -260,7 +263,7 @@ public:
|
||||
void
|
||||
test_keepalive(boost::asio::ip::tcp::endpoint const& ep)
|
||||
{
|
||||
boost::asio::io_service ios;
|
||||
boost::asio::io_context ios;
|
||||
using socket = boost::asio::ip::tcp::socket;
|
||||
socket s(ios);
|
||||
|
||||
@@ -300,10 +303,10 @@ public:
|
||||
sink.threshold(beast::severities::Severity::kAll);
|
||||
beast::Journal journal{sink};
|
||||
TestHandler handler;
|
||||
auto s = make_Server(handler, thread.get_io_service(), journal);
|
||||
auto s = make_Server(handler, thread.get_io_context(), journal);
|
||||
std::vector<Port> serverPort(1);
|
||||
serverPort.back().ip =
|
||||
beast::IP::Address::from_string(getEnvLocalhostAddr()),
|
||||
boost::asio::ip::make_address(getEnvLocalhostAddr()),
|
||||
serverPort.back().port = 0;
|
||||
serverPort.back().protocol.insert("http");
|
||||
auto eps = s->ports(serverPort);
|
||||
@@ -375,10 +378,10 @@ public:
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
TestThread thread;
|
||||
auto s = make_Server(h, thread.get_io_service(), journal);
|
||||
auto s = make_Server(h, thread.get_io_context(), journal);
|
||||
std::vector<Port> serverPort(1);
|
||||
serverPort.back().ip =
|
||||
beast::IP::Address::from_string(getEnvLocalhostAddr()),
|
||||
boost::asio::ip::make_address(getEnvLocalhostAddr()),
|
||||
serverPort.back().port = 0;
|
||||
serverPort.back().protocol.insert("http");
|
||||
s->ports(serverPort);
|
||||
|
||||
Reference in New Issue
Block a user