RESTinio
|
Class for storing the buffers used for streaming body (request/response). More...
#include <buffers.hpp>
Public Member Functions | |
writable_item_t (const writable_item_t &)=delete | |
writable_item_t & | operator= (const writable_item_t &)=delete |
writable_item_t () | |
writable_item_t (const_buffer_t const_buf) | |
template<typename Datasizeable , typename S = typename std::enable_if_t< !std::is_same< std::vector< writable_item_t >, Datasizeable >::value >> | |
writable_item_t (Datasizeable ds) | |
writable_item_t (const char *str) | |
template<typename Datasizeable > | |
writable_item_t (std::shared_ptr< Datasizeable > sp) | |
writable_item_t (sendfile_t sf_opts) | |
writable_item_t (writable_item_t &&b) | |
writable_item_t & | operator= (writable_item_t &&b) |
~writable_item_t () | |
writable_item_type_t | write_type () const noexcept |
Get a type of a stored buffer object. More... | |
std::size_t | size () const |
Get the size of the underlying buffer object. More... | |
asio_ns::const_buffer | buf () const |
Create a buf reference object used by ASIO. More... | |
sendfile_t & | sendfile_operation () |
Get a reference to a sendfile operation. More... | |
Private Types | |
using | storage_t = std::aligned_storage_t< impl::needed_storage_max_size, impl::buffer_storage_align > |
Private Member Functions | |
void | destroy_stored_buffer () |
Access an item as an object of specific types. | |
Casts a stored object to one of the types. | |
const impl::writable_base_t * | get_writable_base () const noexcept |
Access as writable_base_t item. More... | |
impl::writable_base_t * | get_writable_base () noexcept |
Access as writable_base_t item. More... | |
const impl::buf_iface_t * | get_buf () const noexcept |
Access as trivial buf item. More... | |
impl::buf_iface_t * | get_buf () noexcept |
Access as trivial buf item. More... | |
impl::sendfile_write_operation_t * | get_sfwo () noexcept |
Access as sendfile_write_operation_t item. More... | |
Private Attributes | |
writable_item_type_t | m_write_type |
storage_t | m_storage |
A storage for a buffer object of various types. More... | |
Class for storing the buffers used for streaming body (request/response).
Supporting different types of entities that eventually result in output data sent to peer is a bit tricky. In the first step RESTionio distinguish two types of output data sources:
Also trivial buffers are implemented diferently for different cases, includeing a template classes impl::datasizeable_buf_t<Datasizeable>
and impl::shared_datasizeable_buf_t<Datasizeable>
.
When using RESTinio response builder, response body can be constructed using different types of buffers, and once the result is flushed to the connection it must be sent to the socket. A couple of issues arises here. And one of them is how to store all these heterogeneous buffers with fewer allocations and less boilerplate necessary to handle each corner case. Storing and moving a bunch of buffers as a vector would be nice, but vector demands a single type to be used. And writable_item_t represents a custom variant-like abstraction for storing an arbitrary buffer object (std::variant
itself is not the option as it is restricted to types defined beforehand and cannot benifit from the knowledge that all stored items are types derrived from impl::writable_base_t).
For storing the data of buffers m_storage is used. It is an aligned buffer sufficient to store any impl::writable_base_t descendant (there is a limitation concerned with impl::datasizeable_buf_t). Also writable_item_t exposes interface to treat it like a trivial buffer or a sendfile operation. The type of buffer currently stored in writable_item_t instance a write_type() function used.
Having such writable_item_t class, RESTinio can store a sequence of arbitrary buffers in std::vector
.
Definition at line 495 of file buffers.hpp.
|
private |
Definition at line 655 of file buffers.hpp.
|
delete |
|
inline |
Definition at line 501 of file buffers.hpp.
|
inline |
Definition at line 507 of file buffers.hpp.
|
inline |
Definition at line 520 of file buffers.hpp.
|
inline |
Definition at line 530 of file buffers.hpp.
|
inline |
Definition at line 537 of file buffers.hpp.
|
inline |
Definition at line 550 of file buffers.hpp.
|
inline |
Definition at line 556 of file buffers.hpp.
|
inline |
Definition at line 575 of file buffers.hpp.
|
inline |
Create a buf reference object used by ASIO.
Definition at line 594 of file buffers.hpp.
|
inlineprivate |
Definition at line 611 of file buffers.hpp.
|
inlineprivatenoexcept |
Access as trivial buf item.
Definition at line 637 of file buffers.hpp.
|
inlineprivatenoexcept |
Access as trivial buf item.
Definition at line 643 of file buffers.hpp.
|
inlineprivatenoexcept |
Access as sendfile_write_operation_t item.
Definition at line 649 of file buffers.hpp.
|
inlineprivatenoexcept |
Access as writable_base_t item.
Definition at line 625 of file buffers.hpp.
|
inlineprivatenoexcept |
Access as writable_base_t item.
Definition at line 631 of file buffers.hpp.
|
delete |
|
inline |
Definition at line 563 of file buffers.hpp.
|
inline |
Get a reference to a sendfile operation.
Definition at line 604 of file buffers.hpp.
|
inline |
Get the size of the underlying buffer object.
Definition at line 588 of file buffers.hpp.
|
inlinenoexcept |
Get a type of a stored buffer object.
Definition at line 582 of file buffers.hpp.
|
private |
A storage for a buffer object of various types.
Definition at line 661 of file buffers.hpp.
|
private |
Definition at line 617 of file buffers.hpp.