Botan 3.2.0
Crypto and TLS for C&
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator > Class Template Reference

#include <asio_async_ops.h>

Inheritance diagram for Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >:
Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >

Public Types

using allocator_type = boost::asio::associated_allocator_t< Handler, Allocator >
 
using executor_type = boost::asio::associated_executor_t< Handler, Executor1 >
 

Public Member Functions

 AsyncHandshakeOperation (AsyncHandshakeOperation &&)=default
 
template<class HandlerT >
 AsyncHandshakeOperation (HandlerT &&handler, Stream &stream, const boost::system::error_code &ec={})
 
allocator_type get_allocator () const noexcept
 
executor_type get_executor () const noexcept
 
void operator() (boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)
 

Protected Member Functions

template<class... Args>
void complete_now (Args &&... args)
 

Protected Attributes

Handler m_handler
 
boost::asio::executor_work_guard< Executor1 > m_work_guard_1
 

Detailed Description

template<class Handler, class Stream, class Allocator = std::allocator<void>>
class Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >

Definition at line 236 of file asio_async_ops.h.

Member Typedef Documentation

◆ allocator_type

template<class Handler , class Executor1 , class Allocator >
using Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::allocator_type = boost::asio::associated_allocator_t<Handler, Allocator>
inherited

Definition at line 68 of file asio_async_ops.h.

◆ executor_type

template<class Handler , class Executor1 , class Allocator >
using Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::executor_type = boost::asio::associated_executor_t<Handler, Executor1>
inherited

Definition at line 69 of file asio_async_ops.h.

Constructor & Destructor Documentation

◆ AsyncHandshakeOperation() [1/2]

template<class Handler , class Stream , class Allocator = std::allocator<void>>
template<class HandlerT >
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::AsyncHandshakeOperation ( HandlerT &&  handler,
Stream stream,
const boost::system::error_code &  ec = {} 
)
inline

Construct and invoke an AsyncHandshakeOperation.

Parameters
handlerHandler function to be called upon completion.
streamThe stream from which the data will be read
ecOptional error code; used to report an error to the handler function.

Definition at line 246 of file asio_async_ops.h.

246 {}) :
247 AsyncBase<Handler, typename Stream::executor_type, Allocator>(std::forward<HandlerT>(handler),
248 stream.get_executor()),
249 m_stream(stream) {
250 this->operator()(ec, std::size_t(0), false);
251 }
boost::asio::associated_executor_t< Handler, Executor1 > executor_type
executor_type get_executor() const noexcept
AsyncBase(HandlerT &&handler, const Executor1 &executor)
void operator()(boost::system::error_code ec, std::size_t bytesTransferred, bool isContinuation=true)

◆ AsyncHandshakeOperation() [2/2]

template<class Handler , class Stream , class Allocator = std::allocator<void>>
Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::AsyncHandshakeOperation ( AsyncHandshakeOperation< Handler, Stream, Allocator > &&  )
default

Member Function Documentation

◆ complete_now()

template<class Handler , class Executor1 , class Allocator >
template<class... Args>
void Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::complete_now ( Args &&...  args)
inlineprotectedinherited

Call the completion handler.

This function should only be called after an intermediate initiating function has been called.

Parameters
argsArguments forwarded to the completion handler function.

Definition at line 90 of file asio_async_ops.h.

90 {
91 m_work_guard_1.reset();
92 m_handler(std::forward<Args>(args)...);
93 }
boost::asio::executor_work_guard< Executor1 > m_work_guard_1

References Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_handler, and Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_work_guard_1.

Referenced by Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator()(), Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >::operator()(), and Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator()().

◆ get_allocator()

template<class Handler , class Executor1 , class Allocator >
allocator_type Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::get_allocator ( ) const
inlinenoexceptinherited

Definition at line 71 of file asio_async_ops.h.

71{ return boost::asio::get_associated_allocator(m_handler); }

References Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_handler.

◆ get_executor()

template<class Handler , class Executor1 , class Allocator >
executor_type Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::get_executor ( ) const
inlinenoexceptinherited

◆ operator()()

template<class Handler , class Stream , class Allocator = std::allocator<void>>
void Botan::TLS::detail::AsyncHandshakeOperation< Handler, Stream, Allocator >::operator() ( boost::system::error_code  ec,
std::size_t  bytesTransferred,
bool  isContinuation = true 
)
inline

Definition at line 255 of file asio_async_ops.h.

255 {
256 reenter(this) {
257 if(ec == boost::asio::error::eof) {
259 }
260
261 if(bytesTransferred > 0 && !ec) {
262 // Provide encrypted TLS data received from the network to TLS::Channel for decryption
263 boost::asio::const_buffer read_buffer{m_stream.input_buffer().data(), bytesTransferred};
264 m_stream.process_encrypted_data(read_buffer, ec);
265 }
266
267 if(m_stream.has_data_to_send() && !ec) {
268 // Write encrypted TLS data provided by the TLS::Channel on the wire
269
270 // Note: we construct `AsyncWriteOperation` with 0 as its last parameter (`plainBytesTransferred`). This
271 // operation will eventually call `*this` as its own handler, passing the 0 back to this call operator.
272 // This is necessary because the check of `bytesTransferred > 0` assumes that `bytesTransferred` bytes
273 // were just read and are available in input_buffer for further processing.
274 AsyncWriteOperation<AsyncHandshakeOperation<typename std::decay<Handler>::type, Stream, Allocator>,
275 Stream,
276 Allocator>
277 op{std::move(*this), m_stream, 0};
278 return;
279 }
280
281 if(!m_stream.native_handle()->is_active() && !ec) {
282 // Read more encrypted TLS data from the network
283 m_stream.next_layer().async_read_some(m_stream.input_buffer(), std::move(*this));
284 return;
285 }
286
287 if(!isContinuation) {
288 // Make sure the handler is not called without an intermediate initiating function.
289 // "Reading" into a zero-byte buffer will complete immediately.
290 m_ec = ec;
291 yield m_stream.next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*this));
292 ec = m_ec;
293 }
294
295 this->complete_now(ec);
296 }
297 }
native_handle_type native_handle()
const next_layer_type & next_layer() const
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.
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
void complete_now(Args &&... args)
@ StreamTruncated
Definition asio_error.h:33

References Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::complete_now(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send(), Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::native_handle(), Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), and Botan::TLS::StreamTruncated.

Member Data Documentation

◆ m_handler

template<class Handler , class Executor1 , class Allocator >
Handler Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_handler
protectedinherited

◆ m_work_guard_1

template<class Handler , class Executor1 , class Allocator >
boost::asio::executor_work_guard<Executor1> Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::m_work_guard_1
protectedinherited

The documentation for this class was generated from the following file: