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>
67 template <
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>
110 template <
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};
150 static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()
167 if(!m_stream.
has_received_data() && !ec && boost::asio::buffer_size(m_buffers) > 0)
185 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
195 MutableBufferSequence m_buffers;
196 std::size_t m_decodedBytes;
197 boost::system::error_code m_ec;
200 template <
typename Handler,
class Stream,
class Allocator = std::allocator<
void>>
215 template <
class HandlerT>
218 std::size_t plainBytesTransferred,
219 const boost::system::error_code& ec = {})
221 std::forward<HandlerT>(handler),
224 , m_plainBytesTransferred(plainBytesTransferred)
231 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;
266 template <
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(bytesTransferred > 0 && !ec)
299 boost::asio::const_buffer read_buffer {m_stream.
input_buffer().data(), bytesTransferred};
303 static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()
332 op{std::move(*
this), m_stream, 0};
348 yield m_stream.
next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*
this));
358 boost::system::error_code m_ec;
365 #include <boost/asio/unyield.hpp>
367 #endif // BOOST_VERSION
368 #endif // BOTAN_ASIO_ASYNC_OPS_H_
void operator()(boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
AsyncBase(HandlerT &&handler, const Executor1 &executor)
AsyncHandshakeOperation(HandlerT &&handler, Stream &stream, const boost::system::error_code &ec={})
const next_layer_type & next_layer() const
boost::asio::associated_executor_t< Handler, Stream::executor_type > executor_type
virtual ErrorType error_type() const noexcept
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={})
AsyncReadOperation(HandlerT &&handler, Stream &stream, const MutableBufferSequence &buffers, const boost::system::error_code &ec={})
const boost::asio::mutable_buffer & input_buffer()
std::size_t copy_received_data(MutableBufferSequence buffers)
Copy decrypted data into the user-provided buffer.
native_handle_type native_handle()
executor_type get_executor() noexcept
boost::asio compatible SSL/TLS stream
boost::asio::const_buffer send_buffer() const
boost::asio::executor_work_guard< Executor1 > m_work_guard_1
void operator()(boost::system::error_code ec, std::size_t bytes_transferred, bool isContinuation=true)
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
allocator_type get_allocator() const noexcept
bool has_received_data() const
Check if decrypted data is available in the receive buffer.
boost::asio::associated_allocator_t< Handler, Allocator > allocator_type
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
executor_type get_executor() const noexcept
void complete_now(Args &&...args)