20#include <test/jtx/envconfig.h>
22#include <xrpl/basics/make_SSLContext.h>
23#include <xrpl/beast/core/CurrentThreadName.h>
24#include <xrpl/beast/unit_test.h>
26#include <boost/asio/bind_executor.hpp>
27#include <boost/asio/buffer.hpp>
28#include <boost/asio/ip/tcp.hpp>
29#include <boost/asio/read_until.hpp>
30#include <boost/asio/ssl.hpp>
31#include <boost/asio/strand.hpp>
32#include <boost/asio/streambuf.hpp>
33#include <boost/utility/in_place_factory.hpp>
57 using strand_type = boost::asio::strand<io_context_type::executor_type>;
59 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
68 boost::optional<boost::asio::executor_work_guard<
69 boost::asio::io_context::executor_type>>
74 template <
class Streambuf>
78 using boost::asio::buffer;
79 using boost::asio::buffer_copy;
80 using boost::asio::buffer_size;
81 boost::asio::const_buffer buf(s.
data(), s.
size());
82 sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
119 assert(
list_.empty());
126 list_.emplace(child.get(), child);
148 for (
auto const& c :
list_)
150 if (
auto p = c.second.lock())
166 while (!
list_.empty())
194 boost::asio::ip::make_address(
195 test::getEnvLocalhostAddr()),
207 if (!
strand_.running_in_this_thread())
224 std::placeholders::_1)));
232 if (ec != boost::asio::error::operation_aborted)
242 return fail(
"accept", ec);
254 std::placeholders::_1)));
282 if (!
strand_.running_in_this_thread())
297 timer_.async_wait(bind_executor(
302 std::placeholders::_1)));
310 std::placeholders::_1)));
318 if (ec != boost::asio::error::operation_aborted)
319 test_.
log <<
"[server] " << what <<
": " << ec.message()
329 if (ec == boost::asio::error::operation_aborted)
332 return fail(
"timer", ec);
341 return fail(
"handshake", ec);
343 boost::asio::async_read_until(
352 std::placeholders::_1,
353 std::placeholders::_2)));
362 if (ec == boost::asio::error::eof)
365 return stream_.async_shutdown(bind_executor(
370 std::placeholders::_1)));
373 return fail(
"read", ec);
375 buf_.commit(bytes_transferred);
376 buf_.consume(bytes_transferred);
378 boost::asio::async_write(
386 std::placeholders::_1,
387 std::placeholders::_2)));
393 buf_.consume(bytes_transferred);
395 return fail(
"write", ec);
396 stream_.async_shutdown(bind_executor(
401 std::placeholders::_1)));
408 return fail(
"shutdown", ec);
468 if (!
strand_.running_in_this_thread())
483 timer_.async_wait(bind_executor(
488 std::placeholders::_1)));
496 std::placeholders::_1)));
504 if (ec != boost::asio::error::operation_aborted)
505 test_.
log <<
"[client] " << what <<
": " << ec.message()
515 if (ec == boost::asio::error::operation_aborted)
518 return fail(
"timer", ec);
527 return fail(
"connect", ec);
535 std::placeholders::_1)));
542 return fail(
"handshake", ec);
546 boost::asio::async_write(
554 std::placeholders::_1,
555 std::placeholders::_2)));
557 stream_.async_shutdown(bind_executor(
562 std::placeholders::_1)));
569 buf_.consume(bytes_transferred);
571 return fail(
"write", ec);
573 boost::asio::async_read_until(
582 std::placeholders::_1,
583 std::placeholders::_2)));
585 stream_.async_shutdown(bind_executor(
590 std::placeholders::_1)));
598 return fail(
"read", ec);
599 buf_.commit(bytes_transferred);
600 stream_.async_shutdown(bind_executor(
605 std::placeholders::_1)));
612 return fail(
"shutdown", ec);
638 this->io_context_.run();
660BEAST_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::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
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::strand< io_context_type::executor_type > strand_type
boost::asio::ip::tcp::socket socket_type
boost::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
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.
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)