9#ifndef BOTAN_ASIO_ASYNC_OPS_H_
10#define BOTAN_ASIO_ASYNC_OPS_H_
12#include <botan/build.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>
71 using allocator_type = boost::asio::associated_allocator_t<Handler, Allocator>;
72 using executor_type = boost::asio::associated_executor_t<Handler, Executor1>;
76 return boost::asio::get_associated_allocator(
m_handler);
85 template <
class HandlerT>
86 AsyncBase(HandlerT&& handler,
const Executor1& executor)
99 template<
class... Args>
110template <
class Handler,
class Stream,
class MutableBufferSequence,
class Allocator = std::allocator<
void>>
122 template <
class HandlerT>
125 const MutableBufferSequence& buffers,
126 const boost::system::error_code& ec = {})
128 std::forward<HandlerT>(handler),
139 void operator()(boost::system::error_code ec, std::size_t bytes_transferred,
bool isContinuation =
true)
143 if(bytes_transferred > 0 && !ec)
146 boost::asio::const_buffer read_buffer{m_stream.
input_buffer().data(), bytes_transferred};
153 ec = boost::asio::error::eof;
155 else if (ec == boost::asio::error::eof)
161 if(!m_stream.
has_received_data() && !ec && boost::asio::buffer_size(m_buffers) > 0)
179 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
189 MutableBufferSequence m_buffers;
190 std::size_t m_decodedBytes;
191 boost::system::error_code m_ec;
194template <
typename Handler,
class Stream,
class Allocator = std::allocator<
void>>
209 template <
class HandlerT>
212 std::size_t plainBytesTransferred,
213 const boost::system::error_code& ec = {})
215 std::forward<HandlerT>(handler),
218 , m_plainBytesTransferred(plainBytesTransferred)
225 void operator()(boost::system::error_code ec, std::size_t bytes_transferred,
bool isContinuation =
true)
250 yield m_stream.
next_layer().async_write_some(boost::asio::const_buffer(), std::move(*
this));
262 std::size_t m_plainBytesTransferred;
263 boost::system::error_code m_ec;
266template <
class Handler,
class Stream,
class Allocator = std::allocator<
void>>
277 template<
class HandlerT>
281 const boost::system::error_code& ec = {})
283 std::forward<HandlerT>(handler),
292 void operator()(boost::system::error_code ec, std::size_t bytesTransferred,
bool isContinuation =
true)
296 if(ec == boost::asio::error::eof)
301 if(bytesTransferred > 0 && !ec)
304 boost::asio::const_buffer read_buffer {m_stream.
input_buffer().data(), bytesTransferred};
319 op{std::move(*
this), m_stream, 0};
335 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
345 boost::system::error_code m_ec;
352#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