restinio::impl::write_group_output_ctx_t Class Reference

Helper class for writting response data. More...

`#include <write_group_output_ctx.hpp>`

## Classes

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_t > | m_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:

write_group_output_ctx_t output_ctx;
wtite_group_t wg = ...
// Feed write group to context:
output_ctx.start_next_write_group( std::move( wg ) );
try
{
// start handling loop:
for(
// 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 ) );
}
else
{
handle_sendfile( get< file_write_operation_t >( wo ) );
}
}
// Finalize.
output_ctx.finish_write_group();
}
catch( ec ) // asio error code
{
// Loop failed, so we finish write group abnormally.
output_ctx.fail_write_group( ec )
}
restinio::impl::write_group_output_ctx_t::write_group_output_ctx_t
write_group_output_ctx_t()
Contruct an object.
Definition: write_group_output_ctx.hpp:96
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465

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

Definition at line 79 of file write_group_output_ctx.hpp.

## Member Typedef Documentation

## solid_write_operation_variant_t

using restinio::impl::write_group_output_ctx_t::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.

Definition at line 245 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 | ( |  | ) |

inline

Contruct an object.

Definition at line 96 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 | ( |  | ) |

inline

et an object with next write operation to perform.

Definition at line 253 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 | ) |

inline

Handle current group write process failed.

Definition at line 283 of file write_group_output_ctx.hpp.

## finish_write_group()

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

inline

Finish writing group normally.

Definition at line 294 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 | ) |

inline private

Execute notification callback if necessary.

Definition at line 313 of file write_group_output_ctx.hpp.

## max_iov_len()

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

inline static constexpr private noexcept

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

Definition at line 84 of file write_group_output_ctx.hpp.

## prepare_sendfile_wo()

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

inline private

Prepare write operation for sendfile.

Definition at line 358 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 | ( |  | ) |

inline private

Prepare write operation for trivial buffers.

Definition at line 334 of file write_group_output_ctx.hpp.

## reset_write_group()

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

inline private

Reset the write group and associated context.

Definition at line 305 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 | ) |

inline noexcept

Start handlong next write group.

Definition at line 239 of file write_group_output_ctx.hpp.

## transmitting()

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

inline noexcept

Check if data is trunsmitting now.

Definition at line 235 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

private

Asio buffers storage.

Definition at line 377 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

private

Real buffers with data.

Definition at line 367 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 }

private

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 374 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

private

Sendfile operation storage context.

Definition at line 380 of file write_group_output_ctx.hpp.

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

- restinio/impl/write_group_output_ctx.hpp