3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/net/IPAddressConversion.h>
6#include <boost/asio.hpp>
7#include <boost/asio/ip/tcp.hpp>
8#include <boost/asio/ssl.hpp>
9#include <boost/beast/core/bind_handler.hpp>
19 using ssl_socket = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
29 AutoSocket(boost::asio::io_context& s, boost::asio::ssl::context& c,
bool secureOnly,
bool plainOnly)
81 boost::system::error_code
82 cancel(boost::system::error_code& ec)
90 if ((type == ssl_socket::client) || (
mSecure))
94 mSocket->async_handshake(type, cbFunc);
105 mSocket->next_layer().async_receive(
107 boost::asio::socket_base::message_peek,
112 template <
typename ShutdownHandler>
117 mSocket->async_shutdown(handler);
125 catch (boost::system::system_error& e)
129 post(
mSocket->get_executor(), boost::beast::bind_handler(handler, ec));
133 template <
typename Seq,
typename Handler>
138 mSocket->async_read_some(buffers, handler);
143 template <
typename Seq,
typename Condition,
typename Handler>
148 boost::asio::async_read_until(*
mSocket, buffers, condition, handler);
150 boost::asio::async_read_until(
PlainSocket(), buffers, condition, handler);
153 template <
typename Allocator,
typename Handler>
158 boost::asio::async_read_until(*
mSocket, buffers, delim, handler);
160 boost::asio::async_read_until(
PlainSocket(), buffers, delim, handler);
163 template <
typename Allocator,
typename MatchCondition,
typename Handler>
165 async_read_until(boost::asio::basic_streambuf<Allocator>& buffers, MatchCondition cond, Handler handler)
168 boost::asio::async_read_until(*
mSocket, buffers, cond, handler);
170 boost::asio::async_read_until(
PlainSocket(), buffers, cond, handler);
173 template <
typename Buf,
typename Handler>
178 boost::asio::async_write(*
mSocket, buffers, handler);
180 boost::asio::async_write(
PlainSocket(), buffers, handler);
183 template <
typename Allocator,
typename Handler>
185 async_write(boost::asio::basic_streambuf<Allocator>& buffers, Handler handler)
188 boost::asio::async_write(*
mSocket, buffers, handler);
190 boost::asio::async_write(
PlainSocket(), buffers, handler);
193 template <
typename Buf,
typename Condition,
typename Handler>
195 async_read(Buf
const& buffers, Condition cond, Handler handler)
198 boost::asio::async_read(*
mSocket, buffers, cond, handler);
200 boost::asio::async_read(
PlainSocket(), buffers, cond, handler);
203 template <
typename Allocator,
typename Condition,
typename Handler>
205 async_read(boost::asio::basic_streambuf<Allocator>& buffers, Condition cond, Handler handler)
208 boost::asio::async_read(*
mSocket, buffers, cond, handler);
210 boost::asio::async_read(
PlainSocket(), buffers, cond, handler);
213 template <
typename Buf,
typename Handler>
218 boost::asio::async_read(*
mSocket, buffers, handler);
220 boost::asio::async_read(
PlainSocket(), buffers, handler);
223 template <
typename Seq,
typename Handler>
228 mSocket->async_write_some(buffers, handler);
237 using namespace xrpl;
241 JLOG(
j_.
warn()) <<
"Handle autodetect error: " << ec;
246 ((bytesTransferred < 2) || ((
mBuffer[1] < 127) && (
mBuffer[1] > 31))) &&
247 ((bytesTransferred < 3) || ((
mBuffer[2] < 127) && (
mBuffer[2] > 31))) &&
248 ((bytesTransferred < 4) || ((
mBuffer[3] < 127) && (
mBuffer[3] > 31))))
260 mSocket->async_handshake(ssl_socket::server, cbFunc);
void async_write(boost::asio::basic_streambuf< Allocator > &buffers, Handler handler)
AutoSocket(boost::asio::io_context &s, boost::asio::ssl::context &c, bool secureOnly, bool plainOnly)
ssl_socket::handshake_type handshake_type
ssl_socket::lowest_layer_type lowest_layer_type
ssl_socket::next_layer_type plain_socket
boost::asio::ip::tcp::socket::endpoint_type endpoint_type
beast::IP::Endpoint remote_endpoint()
void async_read(boost::asio::basic_streambuf< Allocator > &buffers, Condition cond, Handler handler)
void handle_autodetect(callback cbFunc, error_code const &ec, size_t bytesTransferred)
boost::system::error_code error_code
AutoSocket(boost::asio::io_context &s, boost::asio::ssl::context &c)
void async_handshake(handshake_type type, callback cbFunc)
void async_read_until(boost::asio::basic_streambuf< Allocator > &buffers, MatchCondition cond, Handler handler)
void async_read_until(boost::asio::basic_streambuf< Allocator > &buffers, std::string const &delim, Handler handler)
void async_read(Buf const &buffers, Handler handler)
void async_write(Buf const &buffers, Handler handler)
lowest_layer_type & lowest_layer()
beast::IP::Endpoint local_endpoint()
void async_read_until(Seq const &buffers, Condition condition, Handler handler)
plain_socket & PlainSocket()
void async_read(Buf const &buffers, Condition cond, Handler handler)
void async_read_some(Seq const &buffers, Handler handler)
std::vector< char > mBuffer
void swap(AutoSocket &s) noexcept
void async_write_some(Seq const &buffers, Handler handler)
void async_shutdown(ShutdownHandler handler)
boost::system::error_code cancel(boost::system::error_code &ec)
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > ssl_socket
A version-independent IP address and port combination.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Endpoint from_asio(boost::asio::ip::address const &address)
Convert to Endpoint.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.