9#ifndef BOTAN_ASIO_ASYNC_OPS_H_
10#define BOTAN_ASIO_ASYNC_OPS_H_
12#include <botan/types.h>
14#include <boost/version.hpp>
15#if BOOST_VERSION >= 106600
17 #include <botan/asio_error.h>
21 #define BOOST_ASIO_DISABLE_SERIAL_PORT
22 #include <boost/asio.hpp>
23 #include <boost/asio/yield.hpp>
67template <
class Handler,
class Executor1,
class Allocator>
70 using allocator_type = boost::asio::associated_allocator_t<Handler, Allocator>;
71 using executor_type = boost::asio::associated_executor_t<Handler, Executor1>;
80 template <
class HandlerT>
81 AsyncBase(HandlerT&& handler,
const Executor1& executor) :
91 template <
class... Args>
101template <
class Handler,
class Stream,
class MutableBufferSequence,
class Allocator = std::allocator<
void>>
112 template <
class HandlerT>
115 const MutableBufferSequence& buffers,
116 const boost::system::error_code& ec = {}) :
127 void operator()(boost::system::error_code ec, std::size_t bytes_transferred,
bool isContinuation =
true) {
129 if(bytes_transferred > 0 && !ec) {
131 boost::asio::const_buffer read_buffer{m_stream.
input_buffer().data(), bytes_transferred};
137 ec = boost::asio::error::eof;
138 }
else if(ec == boost::asio::error::eof) {
143 if(!m_stream.
has_received_data() && !ec && boost::asio::buffer_size(m_buffers) > 0) {
154 if(!isContinuation) {
158 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
168 MutableBufferSequence m_buffers;
169 std::size_t m_decodedBytes;
170 boost::system::error_code m_ec;
173template <
typename Handler,
class Stream,
class Allocator = std::allocator<
void>>
187 template <
class HandlerT>
190 std::size_t plainBytesTransferred,
191 const boost::system::error_code& ec = {}) :
195 m_plainBytesTransferred(plainBytesTransferred) {
201 void operator()(boost::system::error_code ec, std::size_t bytes_transferred,
bool isContinuation =
true) {
217 if(!isContinuation) {
221 yield m_stream.
next_layer().async_write_some(boost::asio::const_buffer(), std::move(*
this));
233 std::size_t m_plainBytesTransferred;
234 boost::system::error_code m_ec;
237template <
class Handler,
class Stream,
class Allocator = std::allocator<
void>>
247 template <
class HandlerT>
257 void operator()(boost::system::error_code ec, std::size_t bytesTransferred,
bool isContinuation =
true) {
259 if(ec == boost::asio::error::eof) {
263 if(bytesTransferred > 0 && !ec) {
265 boost::asio::const_buffer read_buffer{m_stream.
input_buffer().data(), bytesTransferred};
279 op{std::move(*
this), m_stream, 0};
289 if(!isContinuation) {
293 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
303 boost::system::error_code m_ec;
310 #include <boost/asio/unyield.hpp>
boost::asio compatible SSL/TLS stream
native_handle_type native_handle()
std::size_t copy_received_data(MutableBufferSequence buffers)
Copy decrypted data into the user-provided buffer.
const next_layer_type & next_layer() const
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
boost::asio::const_buffer send_buffer() const
bool has_received_data() const
Check if decrypted data is available in the receive buffer.
const boost::asio::mutable_buffer & input_buffer()
void process_encrypted_data(const boost::asio::const_buffer &read_buffer, boost::system::error_code &ec)
Pass encrypted data to the native handle for processing.
executor_type get_executor() noexcept
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
boost::asio::associated_executor_t< Handler, Executor1 > executor_type
boost::asio::associated_allocator_t< Handler, Allocator > allocator_type
executor_type get_executor() const noexcept
void complete_now(Args &&... args)
boost::asio::executor_work_guard< Executor1 > m_work_guard_1
AsyncBase(HandlerT &&handler, const Executor1 &executor)
allocator_type get_allocator() const noexcept
AsyncHandshakeOperation(AsyncHandshakeOperation &&)=default
AsyncHandshakeOperation(HandlerT &&handler, Stream &stream, const boost::system::error_code &ec={})
void operator()(boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
void operator()(boost::system::error_code ec, std::size_t bytes_transferred, bool isContinuation=true)
AsyncReadOperation(AsyncReadOperation &&)=default
AsyncReadOperation(HandlerT &&handler, Stream &stream, const MutableBufferSequence &buffers, const boost::system::error_code &ec={})
void operator()(boost::system::error_code ec, std::size_t bytes_transferred, bool isContinuation=true)
AsyncWriteOperation(HandlerT &&handler, Stream &stream, std::size_t plainBytesTransferred, const boost::system::error_code &ec={})
AsyncWriteOperation(AsyncWriteOperation &&)=default