20#include <test/jtx/envconfig.h>
21#include <xrpl/basics/make_SSLContext.h>
22#include <xrpl/beast/core/CurrentThreadName.h>
23#include <xrpl/beast/unit_test.h>
25#include <boost/asio.hpp>
26#include <boost/asio/ssl.hpp>
27#include <boost/utility/in_place_factory.hpp>
55 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
69 template <
class Streambuf>
73 using boost::asio::buffer;
74 using boost::asio::buffer_copy;
75 using boost::asio::buffer_size;
76 boost::asio::const_buffers_1 buf(s.
data(), s.
size());
77 sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
114 assert(
list_.empty());
121 list_.emplace(child.get(), child);
143 for (
auto const& c :
list_)
145 if (
auto p = c.second.lock())
161 while (!
list_.empty())
190 test::getEnvLocalhostAddr()),
202 if (!
strand_.running_in_this_thread())
219 std::placeholders::_1)));
227 if (ec != boost::asio::error::operation_aborted)
237 return fail(
"accept", ec);
249 std::placeholders::_1)));
277 if (!
strand_.running_in_this_thread())
292 timer_.async_wait(bind_executor(
297 std::placeholders::_1)));
305 std::placeholders::_1)));
313 if (ec != boost::asio::error::operation_aborted)
314 test_.
log <<
"[server] " << what <<
": " << ec.message()
324 if (ec == boost::asio::error::operation_aborted)
327 return fail(
"timer", ec);
336 return fail(
"handshake", ec);
338 boost::asio::async_read_until(
347 std::placeholders::_1,
348 std::placeholders::_2)));
357 if (ec == boost::asio::error::eof)
360 return stream_.async_shutdown(bind_executor(
365 std::placeholders::_1)));
368 return fail(
"read", ec);
370 buf_.commit(bytes_transferred);
371 buf_.consume(bytes_transferred);
373 boost::asio::async_write(
381 std::placeholders::_1,
382 std::placeholders::_2)));
388 buf_.consume(bytes_transferred);
390 return fail(
"write", ec);
391 stream_.async_shutdown(bind_executor(
396 std::placeholders::_1)));
403 return fail(
"shutdown", ec);
412 auto const p = std::make_shared<Acceptor>(*
this);
463 if (!
strand_.running_in_this_thread())
478 timer_.async_wait(bind_executor(
483 std::placeholders::_1)));
491 std::placeholders::_1)));
499 if (ec != boost::asio::error::operation_aborted)
500 test_.
log <<
"[client] " << what <<
": " << ec.message()
510 if (ec == boost::asio::error::operation_aborted)
513 return fail(
"timer", ec);
522 return fail(
"connect", ec);
530 std::placeholders::_1)));
537 return fail(
"handshake", ec);
541 boost::asio::async_write(
549 std::placeholders::_1,
550 std::placeholders::_2)));
552 stream_.async_shutdown(bind_executor(
557 std::placeholders::_1)));
564 buf_.consume(bytes_transferred);
566 return fail(
"write", ec);
568 boost::asio::async_read_until(
577 std::placeholders::_1,
578 std::placeholders::_2)));
580 stream_.async_shutdown(bind_executor(
585 std::placeholders::_1)));
593 return fail(
"read", ec);
594 buf_.commit(bytes_transferred);
595 stream_.async_shutdown(bind_executor(
600 std::placeholders::_1)));
607 return fail(
"shutdown", ec);
616 auto const p = std::make_shared<Connection>(*
this, ep);
633 this->io_context_.run();
655BEAST_DEFINE_TESTSUITE(short_read, overlay,
ripple);
log_os< char > log
Logging output stream.
void pass()
Record a successful test condition.
std::map< Child *, std::weak_ptr< Child > > list_
void add(std::shared_ptr< Child > const &child)
void remove(Child *child)
std::condition_variable cond_
Client(short_read_test &test, endpoint_type const &ep)
Server(short_read_test &test)
endpoint_type const & endpoint() const
std::shared_ptr< boost::asio::ssl::context > context_
void run() override
Runs the suite.
boost::asio::io_context::strand strand_type
boost::system::error_code error_code
boost::asio::ssl::stream< socket_type & > stream_type
boost::asio::io_context io_context_type
boost::asio::ip::tcp::endpoint endpoint_type
std::optional< boost::asio::executor_work_guard< boost::asio::executor > > work_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_type
boost::asio::ip::tcp::acceptor acceptor_type
io_context_type io_context_
static void write(Streambuf &sb, std::string const &s)
boost::asio::ip::address address_type
boost::asio::ip::tcp::socket socket_type
T emplace_back(T... args)
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::shared_ptr< boost::asio::ssl::context > make_SSLContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
bool from_string(RangeSet< T > &rs, std::string const &s)
Convert the given styled string to a RangeSet.
T shared_from_this(T... args)
void on_connect(error_code ec)
void on_read(error_code ec, std::size_t bytes_transferred)
void on_write(error_code ec, std::size_t bytes_transferred)
void fail(std::string const &what, error_code ec)
boost::asio::streambuf buf_
endpoint_type const & ep_
Connection(Client &client, endpoint_type const &ep)
void run(endpoint_type const &ep)
void on_shutdown(error_code ec)
void on_timer(error_code ec)
void on_handshake(error_code ec)
void on_accept(error_code ec)
void fail(std::string const &what, error_code ec)
boost::asio::streambuf buf_
void fail(std::string const &what, error_code ec)
void on_timer(error_code ec)
void on_read(error_code ec, std::size_t bytes_transferred)
void on_write(error_code ec, std::size_t bytes_transferred)
void on_shutdown(error_code ec)
Connection(Server &server, socket_type &&socket)
void on_handshake(error_code ec)