20 #ifndef RIPPLE_SERVER_DOOR_H_INCLUDED
21 #define RIPPLE_SERVER_DOOR_H_INCLUDED
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/contract.h>
25 #include <ripple/server/impl/PlainHTTPPeer.h>
26 #include <ripple/server/impl/SSLHTTPPeer.h>
27 #include <ripple/server/impl/io_list.h>
28 #include <boost/asio/basic_waitable_timer.hpp>
29 #include <boost/asio/buffer.hpp>
30 #include <boost/asio/io_context.hpp>
31 #include <boost/asio/ip/tcp.hpp>
32 #include <boost/asio/spawn.hpp>
33 #include <boost/beast/core/detect_ssl.hpp>
34 #include <boost/beast/core/multi_buffer.hpp>
35 #include <boost/beast/core/tcp_stream.hpp>
36 #include <boost/container/flat_map.hpp>
46 template <
class Handler>
52 using timer_type = boost::asio::basic_waitable_timer<clock_type>;
68 boost::asio::io_context&
ioc_;
79 boost::asio::io_context& ioc,
96 boost::asio::io_context&
ioc_;
108 boost::asio::io_context& io_context,
132 template <
class ConstBufferSequence>
136 ConstBufferSequence
const& buffers,
144 template <
class Handler>
148 boost::asio::io_context& ioc,
155 , stream_(
std::move(stream))
156 , socket_(stream_.socket())
157 , remote_address_(remote_address)
163 template <
class Handler>
172 std::placeholders::_1));
175 template <
class Handler>
182 template <
class Handler>
186 boost::beast::multi_buffer buf(16);
188 boost::system::error_code ec;
189 bool const ssl = async_detect_ssl(stream_, buf, do_yield[ec]);
190 stream_.expires_never();
217 if (ec != boost::asio::error::operation_aborted)
219 JLOG(
j_.
trace()) <<
"Error detecting ssl: " << ec.message() <<
" from "
226 template <
class Handler>
238 ss <<
"Can't close acceptor: " <<
port_.
name <<
", "
241 Throw<std::runtime_error>(ss.
str());
247 acceptor_.open(local_address.protocol(), ec);
251 <<
"' failed:" << ec.message();
252 Throw<std::exception>();
256 boost::asio::ip::tcp::acceptor::reuse_address(
true), ec);
260 <<
"' failed:" << ec.message();
261 Throw<std::exception>();
268 <<
"' failed:" << ec.message();
269 Throw<std::exception>();
272 acceptor_.listen(boost::asio::socket_base::max_connections, ec);
276 <<
"' failed:" << ec.message();
277 Throw<std::exception>();
283 template <
class Handler>
286 boost::asio::io_context& io_context,
306 template <
class Handler>
314 this->shared_from_this(),
315 std::placeholders::_1));
318 template <
class Handler>
322 if (!strand_.running_in_this_thread())
331 template <
class Handler>
332 template <
class ConstBufferSequence>
336 ConstBufferSequence
const& buffers,
364 template <
class Handler>
368 while (acceptor_.is_open())
374 acceptor_.async_accept(socket, remote_address, do_yield[ec]);
377 if (ec == boost::asio::error::operation_aborted)
379 JLOG(j_.
error()) <<
"accept: " << ec.message();
380 if (ec == boost::asio::error::no_descriptors)
382 JLOG(j_.
info()) <<
"re-opening acceptor";
390 if (
auto sp = ios().
template emplace<Detector>(
399 else if (ssl_ || plain_)
403 boost::asio::null_buffers{},