1#include <test/jtx/envconfig.h>
3#include <xrpl/basics/make_SSLContext.h>
4#include <xrpl/beast/core/CurrentThreadName.h>
5#include <xrpl/beast/unit_test.h>
7#include <boost/asio/bind_executor.hpp>
8#include <boost/asio/buffer.hpp>
9#include <boost/asio/ip/tcp.hpp>
10#include <boost/asio/read_until.hpp>
11#include <boost/asio/ssl.hpp>
12#include <boost/asio/strand.hpp>
13#include <boost/asio/streambuf.hpp>
14#include <boost/utility/in_place_factory.hpp>
38 using strand_type = boost::asio::strand<io_context_type::executor_type>;
39 using timer_type = boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
48 boost::optional<boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>
work_;
52 template <
class Streambuf>
56 using boost::asio::buffer;
57 using boost::asio::buffer_copy;
58 using boost::asio::buffer_size;
59 boost::asio::const_buffer buf(s.
data(), s.
size());
60 sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
97 assert(
list_.empty());
104 list_.emplace(child.get(), child);
126 for (
auto const& c :
list_)
128 if (
auto p = c.second.lock())
144 while (!
list_.empty())
182 if (!
strand_.running_in_this_thread())
200 if (ec != boost::asio::error::operation_aborted)
210 return fail(
"accept", ec);
244 if (!
strand_.running_in_this_thread())
257 timer_.async_wait(bind_executor(
270 if (ec != boost::asio::error::operation_aborted)
280 if (ec == boost::asio::error::operation_aborted)
283 return fail(
"timer", ec);
292 return fail(
"handshake", ec);
294 boost::asio::async_read_until(
310 if (ec == boost::asio::error::eof)
313 return stream_.async_shutdown(bind_executor(
317 return fail(
"read", ec);
319 buf_.commit(bytes_transferred);
320 buf_.consume(bytes_transferred);
322 boost::asio::async_write(
334 buf_.consume(bytes_transferred);
336 return fail(
"write", ec);
337 stream_.async_shutdown(bind_executor(
345 return fail(
"shutdown", ec);
405 if (!
strand_.running_in_this_thread())
418 timer_.async_wait(bind_executor(
431 if (ec != boost::asio::error::operation_aborted)
441 if (ec == boost::asio::error::operation_aborted)
444 return fail(
"timer", ec);
453 return fail(
"connect", ec);
464 return fail(
"handshake", ec);
468 boost::asio::async_write(
476 stream_.async_shutdown(bind_executor(
484 buf_.consume(bytes_transferred);
486 return fail(
"write", ec);
488 boost::asio::async_read_until(
497 stream_.async_shutdown(bind_executor(
506 return fail(
"read", ec);
507 buf_.commit(bytes_transferred);
508 stream_.async_shutdown(bind_executor(
516 return fail(
"shutdown", ec);
542 this->io_context_.run();
564BEAST_DEFINE_TESTSUITE(short_read, overlay,
xrpl);
log_os< char > log
Logging output stream.
void pass()
Record a successful test condition.
std::map< Child *, std::weak_ptr< Child > > list_
std::condition_variable cond_
void add(std::shared_ptr< Child > const &child)
void remove(Child *child)
Client(short_read_test &test, endpoint_type const &ep)
Server(short_read_test &test)
endpoint_type const & endpoint() const
boost::asio::ip::tcp::endpoint endpoint_type
boost::asio::io_context io_context_type
boost::asio::ip::address address_type
boost::asio::strand< io_context_type::executor_type > strand_type
void run() override
Runs the suite.
io_context_type io_context_
boost::asio::ip::tcp::socket socket_type
boost::system::error_code error_code
std::shared_ptr< boost::asio::ssl::context > context_
boost::asio::ip::tcp::acceptor acceptor_type
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_type
boost::asio::ssl::stream< socket_type & > stream_type
static void write(Streambuf &sb, std::string const &s)
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_timer(error_code ec)
void on_write(error_code ec, std::size_t bytes_transferred)
void on_shutdown(error_code ec)
void run(endpoint_type const &ep)
void on_connect(error_code ec)
void on_handshake(error_code ec)
Connection(Client &client, endpoint_type const &ep)
void fail(std::string const &what, error_code ec)
boost::asio::streambuf buf_
endpoint_type const & ep_
void on_read(error_code ec, std::size_t bytes_transferred)
void on_accept(error_code ec)
void fail(std::string const &what, error_code ec)
void on_handshake(error_code ec)
void on_shutdown(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_timer(error_code ec)
void fail(std::string const &what, error_code ec)
Connection(Server &server, socket_type &&socket)
boost::asio::streambuf buf_