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.hpp>
27#include <boost/asio/ssl.hpp>
28#include <boost/utility/in_place_factory.hpp>
54 boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
68 template <
class Streambuf>
72 using boost::asio::buffer;
73 using boost::asio::buffer_copy;
74 using boost::asio::buffer_size;
75 boost::asio::const_buffers_1 buf(s.
data(), s.
size());
76 sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
113 assert(
list_.empty());
120 list_.emplace(child.get(), child);
142 for (
auto const& c :
list_)
144 if (
auto p = c.second.lock())
160 while (!
list_.empty())
189 test::getEnvLocalhostAddr()),
201 if (!
strand_.running_in_this_thread())
218 std::placeholders::_1)));
226 if (ec != boost::asio::error::operation_aborted)
236 return fail(
"accept", ec);
248 std::placeholders::_1)));
276 if (!
strand_.running_in_this_thread())
291 timer_.async_wait(bind_executor(
296 std::placeholders::_1)));
304 std::placeholders::_1)));
312 if (ec != boost::asio::error::operation_aborted)
313 test_.
log <<
"[server] " << what <<
": " << ec.message()
323 if (ec == boost::asio::error::operation_aborted)
326 return fail(
"timer", ec);
335 return fail(
"handshake", ec);
337 boost::asio::async_read_until(
346 std::placeholders::_1,
347 std::placeholders::_2)));
356 if (ec == boost::asio::error::eof)
359 return stream_.async_shutdown(bind_executor(
364 std::placeholders::_1)));
367 return fail(
"read", ec);
369 buf_.commit(bytes_transferred);
370 buf_.consume(bytes_transferred);
372 boost::asio::async_write(
380 std::placeholders::_1,
381 std::placeholders::_2)));
387 buf_.consume(bytes_transferred);
389 return fail(
"write", ec);
390 stream_.async_shutdown(bind_executor(
395 std::placeholders::_1)));
402 return fail(
"shutdown", ec);
462 if (!
strand_.running_in_this_thread())
477 timer_.async_wait(bind_executor(
482 std::placeholders::_1)));
490 std::placeholders::_1)));
498 if (ec != boost::asio::error::operation_aborted)
499 test_.
log <<
"[client] " << what <<
": " << ec.message()
509 if (ec == boost::asio::error::operation_aborted)
512 return fail(
"timer", ec);
521 return fail(
"connect", ec);
529 std::placeholders::_1)));
536 return fail(
"handshake", ec);
540 boost::asio::async_write(
548 std::placeholders::_1,
549 std::placeholders::_2)));
551 stream_.async_shutdown(bind_executor(
556 std::placeholders::_1)));
563 buf_.consume(bytes_transferred);
565 return fail(
"write", ec);
567 boost::asio::async_read_until(
576 std::placeholders::_1,
577 std::placeholders::_2)));
579 stream_.async_shutdown(bind_executor(
584 std::placeholders::_1)));
592 return fail(
"read", ec);
593 buf_.commit(bytes_transferred);
594 stream_.async_shutdown(bind_executor(
599 std::placeholders::_1)));
606 return fail(
"shutdown", ec);
632 this->io_context_.run();
654BEAST_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)