20 #ifndef RIPPLE_APP_MISC_DETAIL_WORKBASE_H_INCLUDED
21 #define RIPPLE_APP_MISC_DETAIL_WORKBASE_H_INCLUDED
23 #include <ripple/app/misc/detail/Work.h>
24 #include <ripple/protocol/BuildInfo.h>
25 #include <boost/asio.hpp>
26 #include <boost/beast/core/multi_buffer.hpp>
27 #include <boost/beast/http/empty_body.hpp>
28 #include <boost/beast/http/read.hpp>
29 #include <boost/beast/http/write.hpp>
51 boost::beast::http::request<boost::beast::http::empty_body>;
57 boost::asio::io_service&
ios_;
70 boost::asio::io_service& ios,
77 return *
static_cast<Impl*
>(
this);
108 template <
class Impl>
113 boost::asio::io_service& ios,
126 template <
class Impl>
130 cb_(make_error_code(boost::system::errc::not_a_socket),
135 template <
class Impl>
139 if (!strand_.running_in_this_thread())
141 strand_.wrap(
std::bind(&WorkBase::run, impl().shared_from_this())));
143 resolver_.async_resolve(
146 &WorkBase::onResolve,
147 impl().shared_from_this(),
148 std::placeholders::_1,
149 std::placeholders::_2)));
152 template <
class Impl>
156 if (!strand_.running_in_this_thread())
158 return ios_.post(strand_.wrap(
159 std::bind(&WorkBase::cancel, impl().shared_from_this())));
167 template <
class Impl>
173 cb_(ec, std::move(res_));
178 template <
class Impl>
185 socket_.async_connect(
189 impl().shared_from_this(),
190 std::placeholders::_1)));
193 template <
class Impl>
197 req_.method(boost::beast::http::verb::get);
198 req_.target(path_.empty() ?
"/" : path_);
200 req_.set(
"Host", host_ +
":" + port_);
201 req_.set(
"User-Agent", BuildInfo::getFullVersionString());
202 req_.prepare_payload();
203 boost::beast::http::async_write(
207 &WorkBase::onRequest,
208 impl().shared_from_this(),
209 std::placeholders::_1)));
212 template <
class Impl>
219 boost::beast::http::async_read(
224 &WorkBase::onResponse,
225 impl().shared_from_this(),
226 std::placeholders::_1)));
229 template <
class Impl>
238 cb_(ec, std::move(res_));
242 template <
class Impl>
246 if (socket_.is_open())
249 socket_.shutdown(boost::asio::socket_base::shutdown_send, ec);