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

#include <asio_async_ops.h>

Inheritance diagram for Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, 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

 AsyncReadOperation (AsyncReadOperation &&)=default
 
template<class HandlerT >
 AsyncReadOperation (HandlerT &&handler, Stream &stream, const MutableBufferSequence &buffers, 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 bytes_transferred, 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 MutableBufferSequence, class Allocator = std::allocator<void>>
class Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >

Definition at line 111 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 71 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 72 of file asio_async_ops.h.

Constructor & Destructor Documentation

◆ AsyncReadOperation() [1/2]

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

Construct and invoke an AsyncReadOperation.

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

Definition at line 123 of file asio_async_ops.h.

126 {})
127 : AsyncBase<Handler, typename Stream::executor_type, Allocator>(
128 std::forward<HandlerT>(handler),
129 stream.get_executor())
130 , m_stream(stream)
131 , m_buffers(buffers)
132 , m_decodedBytes(0)
133 {
134 this->operator()(ec, std::size_t(0), false);
135 }
void operator()(boost::system::error_code ec, std::size_t bytes_transferred, bool isContinuation=true)

◆ AsyncReadOperation() [2/2]

template<class Handler , class Stream , class MutableBufferSequence , class Allocator = std::allocator<void>>
Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::AsyncReadOperation ( AsyncReadOperation< Handler, Stream, MutableBufferSequence, 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 100 of file asio_async_ops.h.

101 {
102 m_work_guard_1.reset();
103 m_handler(std::forward<Args>(args)...);
104 }
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 74 of file asio_async_ops.h.

75 {
76 return boost::asio::get_associated_allocator(m_handler);
77 }

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 MutableBufferSequence , class Allocator = std::allocator<void>>
void Botan::TLS::detail::AsyncReadOperation< Handler, Stream, MutableBufferSequence, Allocator >::operator() ( boost::system::error_code  ec,
std::size_t  bytes_transferred,
bool  isContinuation = true 
)
inline

Definition at line 139 of file asio_async_ops.h.

140 {
141 reenter(this)
142 {
143 if(bytes_transferred > 0 && !ec)
144 {
145 // We have received encrypted data from the network, now hand it to TLS::Channel for decryption.
146 boost::asio::const_buffer read_buffer{m_stream.input_buffer().data(), bytes_transferred};
147 m_stream.process_encrypted_data(read_buffer, ec);
148 }
149
150 if (m_stream.shutdown_received())
151 {
152 // we just received a 'close_notify' from the peer and don't expect any more data
153 ec = boost::asio::error::eof;
154 }
155 else if (ec == boost::asio::error::eof)
156 {
157 // we did not expect this disconnection from the peer
159 }
160
161 if(!m_stream.has_received_data() && !ec && boost::asio::buffer_size(m_buffers) > 0)
162 {
163 // The channel did not decrypt a complete record yet, we need more data from the socket.
164 m_stream.next_layer().async_read_some(m_stream.input_buffer(), std::move(*this));
165 return;
166 }
167
168 if(m_stream.has_received_data() && !ec)
169 {
170 // The channel has decrypted a TLS record, now copy it to the output buffers.
171 m_decodedBytes = m_stream.copy_received_data(m_buffers);
172 }
173
174 if(!isContinuation)
175 {
176 // Make sure the handler is not called without an intermediate initiating function.
177 // "Reading" into a zero-byte buffer will complete immediately.
178 m_ec = ec;
179 yield m_stream.next_layer().async_read_some(boost::asio::mutable_buffer(), std::move(*this));
180 ec = m_ec;
181 }
182
183 this->complete_now(ec, m_decodedBytes);
184 }
185 }
std::size_t copy_received_data(MutableBufferSequence buffers)
Copy decrypted data into the user-provided buffer.
Definition: asio_stream.h:681
const next_layer_type & next_layer() const
Definition: asio_stream.h:104
bool has_received_data() const
Check if decrypted data is available in the receive buffer.
Definition: asio_stream.h:677
const boost::asio::mutable_buffer & input_buffer()
Definition: asio_stream.h:673
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.
Definition: asio_stream.h:798
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
Definition: asio_stream.h:580
void complete_now(Args &&... args)
@ StreamTruncated
Definition: asio_error.h:35

References Botan::TLS::detail::AsyncBase< Handler, Executor1, Allocator >::complete_now(), Botan::TLS::Stream< StreamLayer, ChannelT >::copy_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_received_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::input_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer(), Botan::TLS::Stream< StreamLayer, ChannelT >::process_encrypted_data(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), 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: