3#include <xrpld/app/misc/detail/Work.h>
5#include <xrpl/basics/random.h>
6#include <xrpl/protocol/BuildInfo.h>
8#include <boost/asio.hpp>
9#include <boost/asio/strand.hpp>
10#include <boost/beast/core/multi_buffer.hpp>
11#include <boost/beast/http/empty_body.hpp>
12#include <boost/beast/http/read.hpp>
13#include <boost/beast/http/write.hpp>
34 using request_type = boost::beast::http::request<boost::beast::http::empty_body>;
40 boost::asio::io_context&
ios_;
41 boost::asio::strand<boost::asio::io_context::executor_type>
strand_;
55 boost::asio::io_context& ios,
64 return *
static_cast<Impl*
>(
this);
103 boost::asio::io_context& ios,
112 , strand_(
boost::asio::make_strand(ios))
115 , lastEndpoint_{lastEndpoint}
116 , lastStatus_(lastStatus)
124 cb_(
make_error_code(boost::system::errc::not_a_socket), lastEndpoint_, std::move(res_));
132 if (!strand_.running_in_this_thread())
133 return boost::asio::post(
135 boost::asio::bind_executor(
138 resolver_.async_resolve(
141 boost::asio::bind_executor(
145 impl().shared_from_this(),
146 std::placeholders::_1,
147 std::placeholders::_2)));
154 if (!strand_.running_in_this_thread())
156 return boost::asio::post(
159 boost::asio::bind_executor(
174 cb_(ec, lastEndpoint_, std::move(res_));
186 boost::asio::async_connect(
189 boost::asio::bind_executor(
193 impl().shared_from_this(),
194 std::placeholders::_1,
195 std::placeholders::_2)));
202 lastEndpoint_ = endpoint;
207 impl().onConnect(ec);
214 req_.method(boost::beast::http::verb::get);
215 req_.target(path_.empty() ?
"/" : path_);
217 req_.set(
"Host", host_ +
":" + port_);
219 req_.prepare_payload();
220 boost::beast::http::async_write(
223 boost::asio::bind_executor(
235 boost::beast::http::async_read(
239 boost::asio::bind_executor(
252 XRPL_ASSERT(cb_,
"xrpl::detail::WorkBase::onResponse : callback is set");
253 cb_(ec, lastEndpoint_, std::move(res_));
261 if (socket_.is_open())
264 socket_.shutdown(boost::asio::socket_base::shutdown_send, ec);
void fail(error_code const &ec)
endpoint_type lastEndpoint_
boost::beast::http::request< boost::beast::http::empty_body > request_type
void onResolve(error_code const &ec, results_type results)
boost::asio::ip::tcp::endpoint endpoint_type
boost::system::error_code error_code
boost::asio::ip::tcp::resolver::results_type results_type
void onRequest(error_code const &ec)
boost::asio::ip::tcp::socket socket_type
void onConnect(error_code const &ec, endpoint_type const &endpoint)
boost::asio::strand< boost::asio::io_context::executor_type > strand_
void onResponse(error_code const &ec)
boost::beast::multi_buffer readBuf_
WorkBase(std::string const &host, std::string const &path, std::string const &port, boost::asio::io_context &ios, endpoint_type const &lastEndpoint, bool lastStatus, callback_type cb)
boost::asio::io_context & ios_
boost::asio::ip::tcp::resolver resolver_type
std::string const & getFullVersionString()
Full server version string.
boost::beast::http::response< boost::beast::http::string_body > response_type
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::error_code make_error_code(xrpl::TokenCodecErrc e)