20#ifndef RIPPLE_APP_MISC_DETAIL_WORKBASE_H_INCLUDED
21#define RIPPLE_APP_MISC_DETAIL_WORKBASE_H_INCLUDED
23#include <xrpld/app/misc/detail/Work.h>
25#include <xrpl/basics/random.h>
26#include <xrpl/protocol/BuildInfo.h>
28#include <boost/asio.hpp>
29#include <boost/asio/strand.hpp>
30#include <boost/beast/core/multi_buffer.hpp>
31#include <boost/beast/http/empty_body.hpp>
32#include <boost/beast/http/read.hpp>
33#include <boost/beast/http/write.hpp>
55 boost::beast::http::request<boost::beast::http::empty_body>;
61 boost::asio::io_context&
ios_;
62 boost::asio::strand<boost::asio::io_context::executor_type>
strand_;
76 boost::asio::io_context& ios,
85 return *
static_cast<Impl*
>(
this);
124 boost::asio::io_context& ios,
133 , strand_(
boost::asio::make_strand(ios))
136 , lastEndpoint_{lastEndpoint}
137 , lastStatus_(lastStatus)
155 if (!strand_.running_in_this_thread())
156 return boost::asio::post(
158 boost::asio::bind_executor(
161 resolver_.async_resolve(
164 boost::asio::bind_executor(
168 impl().shared_from_this(),
169 std::placeholders::_1,
170 std::placeholders::_2)));
177 if (!strand_.running_in_this_thread())
179 return boost::asio::post(
182 boost::asio::bind_executor(
198 cb_(ec, lastEndpoint_, std::move(res_));
210 boost::asio::async_connect(
213 boost::asio::bind_executor(
217 impl().shared_from_this(),
218 std::placeholders::_1,
219 std::placeholders::_2)));
226 lastEndpoint_ = endpoint;
231 impl().onConnect(ec);
238 req_.method(boost::beast::http::verb::get);
239 req_.target(path_.empty() ?
"/" : path_);
241 req_.set(
"Host", host_ +
":" + port_);
243 req_.prepare_payload();
244 boost::beast::http::async_write(
247 boost::asio::bind_executor(
251 impl().shared_from_this(),
252 std::placeholders::_1)));
262 boost::beast::http::async_read(
266 boost::asio::bind_executor(
270 impl().shared_from_this(),
271 std::placeholders::_1)));
282 XRPL_ASSERT(cb_,
"ripple::detail::WorkBase::onResponse : callback is set");
283 cb_(ec, lastEndpoint_, std::move(res_));
291 if (socket_.is_open())
294 socket_.shutdown(boost::asio::socket_base::shutdown_send, ec);
endpoint_type lastEndpoint_
boost::asio::ip::tcp::resolver::results_type results_type
boost::asio::io_context & ios_
boost::beast::http::request< boost::beast::http::empty_body > request_type
void onResolve(error_code const &ec, results_type results)
void onRequest(error_code const &ec)
boost::asio::ip::tcp::socket socket_type
void onResponse(error_code const &ec)
boost::asio::ip::tcp::endpoint endpoint_type
boost::asio::ip::tcp::resolver resolver_type
boost::system::error_code error_code
boost::asio::strand< boost::asio::io_context::executor_type > strand_
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)
void onConnect(error_code const &ec, endpoint_type const &endpoint)
void fail(error_code const &ec)
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(ripple::TokenCodecErrc e)