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);
104 template <
class Impl>
109 boost::asio::io_service& ios,
122 template <
class Impl>
126 cb_(make_error_code(boost::system::errc::not_a_socket),
130 template <
class Impl>
134 if (!strand_.running_in_this_thread())
136 strand_.wrap(
std::bind(&WorkBase::run, impl().shared_from_this())));
138 resolver_.async_resolve(
141 &WorkBase::onResolve,
142 impl().shared_from_this(),
143 std::placeholders::_1,
144 std::placeholders::_2)));
147 template <
class Impl>
151 if (!strand_.running_in_this_thread())
153 return ios_.post(strand_.wrap(
154 std::bind(&WorkBase::cancel, impl().shared_from_this())));
162 template <
class Impl>
168 cb_(ec, std::move(res_));
173 template <
class Impl>
180 socket_.async_connect(
184 impl().shared_from_this(),
185 std::placeholders::_1)));
188 template <
class Impl>
192 req_.method(boost::beast::http::verb::get);
193 req_.target(path_.empty() ?
"/" : path_);
195 req_.set(
"Host", host_ +
":" + port_);
196 req_.set(
"User-Agent", BuildInfo::getFullVersionString());
197 req_.prepare_payload();
198 boost::beast::http::async_write(
202 &WorkBase::onRequest,
203 impl().shared_from_this(),
204 std::placeholders::_1)));
207 template <
class Impl>
214 boost::beast::http::async_read(
219 &WorkBase::onResponse,
220 impl().shared_from_this(),
221 std::placeholders::_1)));
224 template <
class Impl>
232 cb_(ec, std::move(res_));