Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
restinio::impl::write_group_output_ctx_t Class Reference

Helper class for writting response data. More...

#include <write_group_output_ctx.hpp>


class  file_write_operation_t
 Write operaton using sendfile. More...
struct  none_write_operation_t
 None write operation. More...
class  trivial_write_operation_t
 Trivial write operaton. More...

Public Types

using solid_write_operation_variant_t = variant_t< none_write_operation_t, trivial_write_operation_t, file_write_operation_t >
 An alias for variant holding write operation specifics. More...

Public Member Functions

 write_group_output_ctx_t ()
 Contruct an object. More...
bool transmitting () const noexcept
 Check if data is trunsmitting now. More...
void start_next_write_group (optional_t< write_group_t > next_wg) noexcept
 Start handlong next write group. More...
solid_write_operation_variant_t extract_next_write_operation ()
 et an object with next write operation to perform. More...
void fail_write_group (const asio_ns::error_code &ec)
 Handle current group write process failed. More...
void finish_write_group ()
 Finish writing group normally. More...

Private Member Functions

void reset_write_group ()
 Reset the write group and associated context. More...
void invoke_after_write_notificator_if_necessary (const asio_ns::error_code &ec)
 Execute notification callback if necessary. More...
trivial_write_operation_t prepare_trivial_buffers_wo ()
 Prepare write operation for trivial buffers. More...
file_write_operation_t prepare_sendfile_wo ()
 Prepare write operation for sendfile. More...

Static Private Member Functions

static constexpr auto max_iov_len () noexcept
 Get the maximum number of buffers that can be written with gather write operation. More...

Private Attributes

optional_t< write_group_tm_current_wg
 Real buffers with data. More...
std::size_t m_next_writable_item_index { 0 }
 Keeps track of the next writable item stored in m_current_wg. More...
asio_bufs_container_t m_asio_bufs
 Asio buffers storage. More...
sendfile_operation_shared_ptr_t m_sendfile_operation
 Sendfile operation storage context. More...

Detailed Description

Helper class for writting response data.

The usage scenario is some kind of the following:

wtite_group_t wg = ...
// Feed write group to context:
output_ctx.start_next_write_group( std::move( wg ) );
// start handling loop:
// Extract next solid output piece.
auto wo = output_ctx.extract_next_write_operation();
// Are we done with consuming a given write_group_t instance?
!holds_alternative< none_write_operation_t >( wo );
// Get next output piece.
wo = output_ctx.extract_next_write_operation() )
if( holds_alternative< trivial_write_operation_t >( wo ) )
handle_trivial_bufs( get< trivial_write_operation_t >( wo ) );
handle_sendfile( get< file_write_operation_t >( wo ) );
// Finalize.
catch( ec ) // asio error code
// Loop failed, so we finish write group abnormally.
output_ctx.fail_write_group( ec )

Of course, the real usage is complicated by spreading in time and running plenty of other logic cooperatively.

Definition at line 77 of file write_group_output_ctx.hpp.

Member Typedef Documentation

◆ solid_write_operation_variant_t

An alias for variant holding write operation specifics.

Definition at line 242 of file write_group_output_ctx.hpp.

Constructor & Destructor Documentation

◆ write_group_output_ctx_t()

restinio::impl::write_group_output_ctx_t::write_group_output_ctx_t ( )

Contruct an object.

Definition at line 93 of file write_group_output_ctx.hpp.

Member Function Documentation

◆ extract_next_write_operation()

solid_write_operation_variant_t restinio::impl::write_group_output_ctx_t::extract_next_write_operation ( )

et an object with next write operation to perform.

Definition at line 246 of file write_group_output_ctx.hpp.

◆ fail_write_group()

void restinio::impl::write_group_output_ctx_t::fail_write_group ( const asio_ns::error_code &  ec)

Handle current group write process failed.

Definition at line 276 of file write_group_output_ctx.hpp.

◆ finish_write_group()

void restinio::impl::write_group_output_ctx_t::finish_write_group ( )

Finish writing group normally.

Definition at line 287 of file write_group_output_ctx.hpp.

◆ invoke_after_write_notificator_if_necessary()

void restinio::impl::write_group_output_ctx_t::invoke_after_write_notificator_if_necessary ( const asio_ns::error_code &  ec)

Execute notification callback if necessary.

Definition at line 306 of file write_group_output_ctx.hpp.

◆ max_iov_len()

static constexpr auto restinio::impl::write_group_output_ctx_t::max_iov_len ( )

Get the maximum number of buffers that can be written with gather write operation.

Definition at line 82 of file write_group_output_ctx.hpp.

◆ prepare_sendfile_wo()

file_write_operation_t restinio::impl::write_group_output_ctx_t::prepare_sendfile_wo ( )

Prepare write operation for sendfile.

Definition at line 351 of file write_group_output_ctx.hpp.

◆ prepare_trivial_buffers_wo()

trivial_write_operation_t restinio::impl::write_group_output_ctx_t::prepare_trivial_buffers_wo ( )

Prepare write operation for trivial buffers.

Definition at line 327 of file write_group_output_ctx.hpp.

◆ reset_write_group()

void restinio::impl::write_group_output_ctx_t::reset_write_group ( )

Reset the write group and associated context.

Definition at line 298 of file write_group_output_ctx.hpp.

◆ start_next_write_group()

void restinio::impl::write_group_output_ctx_t::start_next_write_group ( optional_t< write_group_t next_wg)

Start handlong next write group.

Definition at line 232 of file write_group_output_ctx.hpp.

◆ transmitting()

bool restinio::impl::write_group_output_ctx_t::transmitting ( ) const

Check if data is trunsmitting now.

Definition at line 228 of file write_group_output_ctx.hpp.

Member Data Documentation

◆ m_asio_bufs

asio_bufs_container_t restinio::impl::write_group_output_ctx_t::m_asio_bufs

Asio buffers storage.

Definition at line 370 of file write_group_output_ctx.hpp.

◆ m_current_wg

optional_t< write_group_t > restinio::impl::write_group_output_ctx_t::m_current_wg

Real buffers with data.

Definition at line 360 of file write_group_output_ctx.hpp.

◆ m_next_writable_item_index

std::size_t restinio::impl::write_group_output_ctx_t::m_next_writable_item_index { 0 }

Keeps track of the next writable item stored in m_current_wg.

When emitting next solid write operation we need to know where the next starting item is.

Definition at line 367 of file write_group_output_ctx.hpp.

◆ m_sendfile_operation

sendfile_operation_shared_ptr_t restinio::impl::write_group_output_ctx_t::m_sendfile_operation

Sendfile operation storage context.

Definition at line 373 of file write_group_output_ctx.hpp.

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