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

#include <asio_async_ops.h>

Inheritance diagram for Botan::TLS::detail::AsyncWriteOperation< Handler, Stream, Allocator >:
Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >

Public Types

using allocator_type = boost::asio::associated_allocator_t< Handler, std::allocator< void > >
 
using executor_type = boost::asio::associated_executor_t< Handler, Stream::executor_type >
 

Public Member Functions

 AsyncWriteOperation (AsyncWriteOperation &&)=default
 
template<class HandlerT >
 AsyncWriteOperation (HandlerT &&handler, Stream &stream, std::size_t plainBytesTransferred, 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

void complete_now (Args &&... args)
 

Protected Attributes

Handler m_handler
 
boost::asio::executor_work_guard< Stream::executor_typem_work_guard_1
 

Detailed Description

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

Definition at line 195 of file asio_async_ops.h.

Member Typedef Documentation

◆ allocator_type

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::allocator_type = boost::asio::associated_allocator_t<Handler, std::allocator< void > >
inherited

Definition at line 71 of file asio_async_ops.h.

◆ executor_type

using Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::executor_type = boost::asio::associated_executor_t<Handler, Stream::executor_type >
inherited

Definition at line 72 of file asio_async_ops.h.

Constructor & Destructor Documentation

◆ AsyncWriteOperation() [1/2]

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

Construct and invoke an AsyncWriteOperation.

Parameters
handlerHandler function to be called upon completion.
streamThe stream from which the data will be read
plainBytesTransferredNumber of bytes to be reported to the user-provided handler function as bytes_transferred. This needs to be provided since the amount of plaintext data consumed from the input buffer can differ from the amount of encrypted data written to the next layer.
ecOptional error code; used to report an error to the handler function.

Definition at line 210 of file asio_async_ops.h.

213 {})
214 : AsyncBase<Handler, typename Stream::executor_type, Allocator>(
215 std::forward<HandlerT>(handler),
216 stream.get_executor())
217 , m_stream(stream)
218 , m_plainBytesTransferred(plainBytesTransferred)
219 {
220 this->operator()(ec, std::size_t(0), false);
221 }
void operator()(boost::system::error_code ec, std::size_t bytes_transferred, bool isContinuation=true)

◆ AsyncWriteOperation() [2/2]

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

Member Function Documentation

◆ complete_now()

void Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::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< Stream::executor_type > m_work_guard_1

◆ get_allocator()

allocator_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::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 }

◆ get_executor()

executor_type Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::get_executor ( ) const
inlinenoexceptinherited

Definition at line 79 of file asio_async_ops.h.

80 {
81 return boost::asio::get_associated_executor(m_handler, m_work_guard_1.get_executor());
82 }

◆ operator()()

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

Definition at line 225 of file asio_async_ops.h.

226 {
227 reenter(this)
228 {
229 // mark the number of encrypted bytes sent to the network as "consumed"
230 // Note: bytes_transferred will be zero on first call
231 m_stream.consume_send_buffer(bytes_transferred);
232
233 if(m_stream.has_data_to_send() && !ec)
234 {
235 m_stream.next_layer().async_write_some(m_stream.send_buffer(), std::move(*this));
236 return;
237 }
238
239 if (ec == boost::asio::error::eof && !m_stream.shutdown_received())
240 {
241 // transport layer was closed by peer without receiving 'close_notify'
243 }
244
245 if(!isContinuation)
246 {
247 // Make sure the handler is not called without an intermediate initiating function.
248 // "Writing" to a zero-byte buffer will complete immediately.
249 m_ec = ec;
250 yield m_stream.next_layer().async_write_some(boost::asio::const_buffer(), std::move(*this));
251 ec = m_ec;
252 }
253
254 // The size of the sent TLS record can differ from the size of the payload due to TLS encryption. We need to
255 // tell the handler how many bytes of the original data we already processed.
256 this->complete_now(ec, m_plainBytesTransferred);
257 }
258 }
const next_layer_type & next_layer() const
Definition: asio_stream.h:106
void consume_send_buffer(std::size_t bytesConsumed)
Mark bytes in the send buffer as consumed, removing them from the buffer.
Definition: asio_stream.h:675
boost::asio::const_buffer send_buffer() const
Definition: asio_stream.h:653
bool shutdown_received() const
Indicates whether a close_notify alert has been received from the peer.
Definition: asio_stream.h:569
bool has_data_to_send() const
Check if encrypted data is available in the send buffer.
Definition: asio_stream.h:672
@ StreamTruncated
Definition: asio_error.h:35

References Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type, std::allocator< void > >::complete_now(), Botan::TLS::Stream< StreamLayer, ChannelT >::consume_send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::has_data_to_send(), Botan::TLS::Stream< StreamLayer, ChannelT >::next_layer(), Botan::TLS::Stream< StreamLayer, ChannelT >::send_buffer(), Botan::TLS::Stream< StreamLayer, ChannelT >::shutdown_received(), and Botan::TLS::StreamTruncated.

Member Data Documentation

◆ m_handler

Handler Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::m_handler
protectedinherited

Definition at line 106 of file asio_async_ops.h.

◆ m_work_guard_1

boost::asio::executor_work_guard<Stream::executor_type > Botan::TLS::detail::AsyncBase< Handler, Stream::executor_type , std::allocator< void > >::m_work_guard_1
protectedinherited

Definition at line 107 of file asio_async_ops.h.


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