buffers.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <memory>
#include <array>
#include <string>
#include <cstring>
#include <type_traits>
#include <restinio/asio_include.hpp>
#include <restinio/exception.hpp>
#include <restinio/sendfile.hpp>
#include <restinio/compiler_features.hpp>
#include <restinio/utils/suppress_exceptions.hpp>
#include <restinio/utils/impl/safe_uint_truncate.hpp>
#include <restinio/impl/include_fmtlib.hpp>
namespace restinio
{
//
// fmt_minimal_memory_buffer_t
//
using fmt_minimal_memory_buffer_t = fmt::basic_memory_buffer<char, 1u>;
namespace impl
{
//
// writable_base_t
//
class writable_base_t
{
public:
writable_base_t() = default;
writable_base_t( const writable_base_t & ) = default;
writable_base_t( writable_base_t && ) = default;
writable_base_t & operator = ( const writable_base_t & ) = delete;
writable_base_t & operator = ( writable_base_t && ) = delete;
virtual ~writable_base_t()
{}
virtual void relocate_to( void * storage ) = 0;
virtual std::size_t size() const = 0;
};
class buf_iface_t : public writable_base_t
{
public:
virtual asio_ns::const_buffer buffer() const = 0;
};
class empty_buf_t final : public buf_iface_t
{
public:
empty_buf_t() noexcept {}
empty_buf_t( const empty_buf_t & ) = delete;
empty_buf_t & operator = ( const empty_buf_t & ) = delete;
empty_buf_t( empty_buf_t && ) = default; // allow only explicit move.
empty_buf_t & operator = ( empty_buf_t && ) = delete;
virtual asio_ns::const_buffer buffer() const override
{
return asio_ns::const_buffer{ nullptr, 0 };
}
virtual void relocate_to( void * storage ) override
{
new( storage ) empty_buf_t{};
}
virtual std::size_t size() const override { return 0; }
};
class const_buf_t final : public buf_iface_t
{
public:
const_buf_t() = delete;
constexpr const_buf_t( const void * data, std::size_t size ) noexcept
: m_data{ data }
, m_size{ size }
{}
const_buf_t( const const_buf_t & ) = delete;
const_buf_t & operator = ( const const_buf_t & ) = delete;
const_buf_t( const_buf_t && ) = default; // allow only explicit move.
const_buf_t & operator = ( const_buf_t && ) = delete;
virtual asio_ns::const_buffer buffer() const override
{
return asio_ns::const_buffer{ m_data, m_size };
}
virtual void relocate_to( void * storage ) override
{
new( storage ) const_buf_t{ std::move( *this ) };
}
virtual std::size_t size() const override { return m_size; }
private:
const void * const m_data;
const std::size_t m_size;
};
template < typename Datasizeable >
class datasizeable_buf_t final : public buf_iface_t
{
// Check datasizeable contract:
static_assert(
std::is_convertible<
decltype( std::declval< const Datasizeable >().data() ),
const void *
>::value,
"Datasizeable requires 'T* data() const' member function, "
"where 'T*' is convertible to 'void*' " );
static_assert(
std::is_convertible<
decltype( std::declval< const Datasizeable >().size() ),
std::size_t
>::value,
"Datasizeable requires 'N size() const' member function, "
"where 'N' is convertible to 'std::size_t'" );
static_assert(
std::is_move_constructible< Datasizeable >::value,
"Datasizeable must be move constructible" );
public:
datasizeable_buf_t( Datasizeable buf )
: m_custom_buffer{ std::move( buf ) }
{}
datasizeable_buf_t( datasizeable_buf_t && ) noexcept = default; // allow only explicit move.
virtual asio_ns::const_buffer buffer() const override
{
return asio_ns::const_buffer{
m_custom_buffer.data(),
m_custom_buffer.size() };
}
virtual void relocate_to( void * storage ) override
{
new( storage ) datasizeable_buf_t{ std::move( *this ) };
}
virtual std::size_t size() const override { return m_custom_buffer.size(); }
private:
Datasizeable m_custom_buffer;
};
using string_buf_t = datasizeable_buf_t< std::string >;
using fmt_minimal_memory_buffer_buf_t =
datasizeable_buf_t< fmt_minimal_memory_buffer_t >;
//
// shared_datasizeable_buf_t
//
template < typename Datasizeable >
class shared_datasizeable_buf_t final : public buf_iface_t
{
public:
using shared_ptr_t = std::shared_ptr< Datasizeable >;
shared_datasizeable_buf_t() = delete;
shared_datasizeable_buf_t( shared_ptr_t buf_ptr ) noexcept
: m_buf_ptr{ std::move( buf_ptr ) }
{}
shared_datasizeable_buf_t( const shared_datasizeable_buf_t & ) = delete;
shared_datasizeable_buf_t & operator = ( const shared_datasizeable_buf_t & ) = delete;
shared_datasizeable_buf_t( shared_datasizeable_buf_t && ) noexcept = default; // allow only explicit move.
shared_datasizeable_buf_t & operator = ( shared_datasizeable_buf_t && ) = delete;
virtual asio_ns::const_buffer buffer() const override
{
return asio_ns::const_buffer{ m_buf_ptr->data(), m_buf_ptr->size() };
}
virtual void relocate_to( void * storage ) override
{
new( storage ) shared_datasizeable_buf_t{ std::move( *this ) };
}
virtual std::size_t size() const override { return m_buf_ptr->size(); }
private:
shared_ptr_t m_buf_ptr;
};
//
// sendfile_write_operation_t
//
struct sendfile_write_operation_t : public writable_base_t
{
public:
sendfile_write_operation_t() = delete;
sendfile_write_operation_t( sendfile_t && sf_opts )
: m_sendfile_options{ std::make_unique< sendfile_t >( std::move( sf_opts ) ) }
{}
sendfile_write_operation_t( const sendfile_write_operation_t & ) = delete;
sendfile_write_operation_t & operator = ( const sendfile_write_operation_t & ) = delete;
sendfile_write_operation_t( sendfile_write_operation_t && ) = default;
sendfile_write_operation_t & operator = ( sendfile_write_operation_t && ) = delete;
virtual void relocate_to( void * storage ) override
{
new( storage ) sendfile_write_operation_t{ std::move( *this ) };
}
virtual std::size_t size() const override
{
return m_sendfile_options
? ::restinio::utils::impl::uint64_to_size_t(
m_sendfile_options->size())
: std::size_t{ 0 };
}
sendfile_t &
sendfile_options() noexcept
{
return *m_sendfile_options;
}
private:
std::unique_ptr< sendfile_t > m_sendfile_options;
};
// Constant for suitable alignment of any entity in writable_base_t hierarchy.
constexpr std::size_t buffer_storage_align =
std::max< std::size_t >( {
alignof( empty_buf_t ),
alignof( const_buf_t ),
alignof( string_buf_t ),
alignof( shared_datasizeable_buf_t< std::string > ),
alignof( sendfile_write_operation_t ),
alignof( fmt_minimal_memory_buffer_buf_t ) } );
constexpr std::size_t needed_storage_max_size =
std::max< std::size_t >( {
sizeof( empty_buf_t ),
sizeof( const_buf_t ),
sizeof( string_buf_t ),
sizeof( shared_datasizeable_buf_t< std::string > ),
sizeof( sendfile_write_operation_t ),
sizeof( fmt_minimal_memory_buffer_buf_t ) } );
} /* namespace impl */
//
// const_buffer_t/
/*
A proxy DTO type.
Its instances are emitted with const_buffer functions and
are possible to converted to writable_item_t as it has a constructor for it.
*/
struct const_buffer_t
{
constexpr const_buffer_t(
const void * str,
std::size_t size ) noexcept
: m_str{ str }
, m_size{ size }
{}
const void * const m_str;
const std::size_t m_size;
};
inline constexpr const_buffer_t
const_buffer( const void * str, std::size_t size ) noexcept
{
return const_buffer_t{ str, size };
}
inline const_buffer_t
const_buffer( const char * str ) noexcept
{
return const_buffer( str, std::strlen( str ) );
}
//
// writable_item_type_t
//
enum class writable_item_type_t
{
trivial_write_operation,
file_write_operation,
};
//
// writable_item_t
//
class writable_item_t
{
public:
writable_item_t( const writable_item_t & ) = delete;
writable_item_t & operator = ( const writable_item_t & ) = delete;
writable_item_t()
: m_write_type{ writable_item_type_t::trivial_write_operation }
{
new( &m_storage ) impl::empty_buf_t{};
}
writable_item_t( const_buffer_t const_buf )
: m_write_type{ writable_item_type_t::trivial_write_operation }
{
new( &m_storage ) impl::const_buf_t{ const_buf.m_str, const_buf.m_size };
}
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 )
: m_write_type{ writable_item_type_t::trivial_write_operation }
{
static_assert(
sizeof( impl::datasizeable_buf_t< Datasizeable > ) <= impl::needed_storage_max_size,
"size of type is too big" );
new( &m_storage ) impl::datasizeable_buf_t< Datasizeable >{ std::move( ds ) };
}
writable_item_t( const char * str )
// We can't be sure whether it is valid to consider
// data pointed by str a const buffer, so we make a string copy here.
: writable_item_t{ std::string{ str } }
{}
template < typename Datasizeable >
writable_item_t( std::shared_ptr< Datasizeable > sp )
: m_write_type{ writable_item_type_t::trivial_write_operation }
{
static_assert(
sizeof( impl::shared_datasizeable_buf_t< Datasizeable > ) <= impl::needed_storage_max_size,
"size of shared_ptr on a type is too big" );
if( !sp )
throw exception_t{ "empty shared_ptr cannot be used as buffer" };
new( &m_storage ) impl::shared_datasizeable_buf_t< Datasizeable >{ std::move( sp ) };
}
writable_item_t( sendfile_t sf_opts )
: m_write_type{ writable_item_type_t::file_write_operation }
{
new( &m_storage ) impl::sendfile_write_operation_t{ std::move( sf_opts ) };
}
writable_item_t( writable_item_t && b )
: m_write_type{ b.m_write_type }
{
b.get_writable_base()->relocate_to( &m_storage );
}
writable_item_t &
operator = ( writable_item_t && b )
{
if( this != &b )
{
destroy_stored_buffer();
m_write_type = b.m_write_type;
b.get_writable_base()->relocate_to( &m_storage );
}
return *this;
}
~writable_item_t()
{
destroy_stored_buffer();
}
writable_item_type_t
write_type() const noexcept
{
return m_write_type;
}
std::size_t size() const { return get_writable_base()->size(); }
asio_ns::const_buffer buf() const { return get_buf()->buffer(); }
sendfile_t &
sendfile_operation()
{
return get_sfwo()->sendfile_options();
}
private:
void
destroy_stored_buffer()
{
using dtor_writable_base_t = impl::writable_base_t;
get_writable_base()->~dtor_writable_base_t();
}
writable_item_type_t m_write_type;
const impl::writable_base_t * get_writable_base() const noexcept
{
return reinterpret_cast< const impl::writable_base_t * >( &m_storage );
}
impl::writable_base_t * get_writable_base() noexcept
{
return reinterpret_cast< impl::writable_base_t * >( &m_storage );
}
const impl::buf_iface_t * get_buf() const noexcept
{
return reinterpret_cast< const impl::buf_iface_t * >( &m_storage );
}
impl::buf_iface_t * get_buf() noexcept
{
return reinterpret_cast< impl::buf_iface_t * >( &m_storage );
}
impl::sendfile_write_operation_t * get_sfwo() noexcept
{
return reinterpret_cast< impl::sendfile_write_operation_t * >( &m_storage );
}
using storage_t =
std::aligned_storage_t<
impl::needed_storage_max_size,
impl::buffer_storage_align >;
storage_t m_storage;
};
//
// writable_items_container_t
//
using writable_items_container_t = std::vector< writable_item_t >;
//
// write_status_cb_t
//
using write_status_cb_t =
std::function< void( const asio_ns::error_code & ec ) >;
//
// write_group_t
//
class write_group_t
{
public:
friend void
swap( write_group_t & left, write_group_t & right ) noexcept
{
using std::swap;
swap( left.m_items, right.m_items );
swap( left.m_status_line_size, right.m_status_line_size );
swap( left.m_after_write_notificator, right.m_after_write_notificator );
}
explicit write_group_t(
writable_items_container_t items ) noexcept
: m_items{ std::move( items ) }
, m_status_line_size{ 0 }
{}
write_group_t( const write_group_t & ) = delete;
write_group_t & operator = ( const write_group_t & ) = delete;
write_group_t( write_group_t && wg ) noexcept
: m_items{ std::move( wg.m_items ) }
, m_status_line_size{ wg.m_status_line_size }
, m_after_write_notificator{ std::move( wg.m_after_write_notificator ) }
{
wg.m_after_write_notificator = write_status_cb_t{}; // Make sure src is cleaned.
wg.m_status_line_size = 0;
}
write_group_t & operator = ( write_group_t && wg ) noexcept
{
write_group_t tmp{ std::move( wg ) };
swap( *this, tmp );
return *this;
}
~write_group_t() noexcept
{
if( m_after_write_notificator )
{
restinio::utils::suppress_exceptions_quietly( [&] {
invoke_after_write_notificator_if_exists(
make_asio_compaible_error(
asio_convertible_error_t::write_group_destroyed_passively ) );
} );
}
}
void
status_line_size( std::size_t n )
{
if( std::size_t{0} != n )
{
if( m_items.empty() )
{
throw exception_t{
"cannot set status line size for empty write group" };
}
if( writable_item_type_t::trivial_write_operation !=
m_items.front().write_type() )
{
throw exception_t{
"cannot set status line size for write group: "
"first writable item must be 'trivial_write_operation'" };
}
if( m_items.front().size() < n )
{
throw exception_t{
"cannot set status line size for write group: "
"first writable item size is less than provided value" };
}
m_status_line_size = n;
}
}
std::size_t
status_line_size() const noexcept
{
return m_status_line_size;
}
void
after_write_notificator( write_status_cb_t notificator ) noexcept
{
m_after_write_notificator = std::move( notificator );
}
bool
has_after_write_notificator() const noexcept
{
return static_cast< bool >( m_after_write_notificator );
}
void
invoke_after_write_notificator_if_exists( const asio_ns::error_code & ec )
{
if( m_after_write_notificator )
{
auto tmp = std::move( m_after_write_notificator );
// Make sure we clean notificator,
// because on some platforms/compilers `std::move()` does not clean it.
m_after_write_notificator = write_status_cb_t{};
tmp( ec );
}
}
auto
items_count() const noexcept
{
return m_items.size();
}
const auto &
items() const noexcept
{
return m_items;
}
auto &
items() noexcept
{
return m_items;
}
void
reset() noexcept
{
RESTINIO_ENSURE_NOEXCEPT_CALL( m_items.clear() );
m_status_line_size = 0;
// This assign is expected to be noexcept.
// And it is on some compilers.
// But for some compilers std::function::operator= is not noexcept
// (for example for Visual C++ from VisualStudio 2017).
// So we have to hope that this assign won't throw.
// Otherwise there is no way to recover from an exception
// from std::function::operator= in that place.
m_after_write_notificator = write_status_cb_t{};
}
void
merge( write_group_t second )
{
auto & second_items = second.m_items;
m_items.reserve( m_items.size() + second_items.size() );
std::move(
begin( second_items ),
end( second_items ),
std::back_inserter( m_items ) );
m_after_write_notificator = std::move( second.m_after_write_notificator );
}
private:
writable_items_container_t m_items;
std::size_t m_status_line_size;
write_status_cb_t m_after_write_notificator;
};
} /* namespace restinio */
asio_include.hpp
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::impl::buf_iface_t
Internal interface for a trivial buffer-like entity.
Definition: buffers.hpp:81
restinio::impl::buf_iface_t::buffer
virtual asio_ns::const_buffer buffer() const =0
Get asio buf entity.
restinio::impl::const_buf_t
Buffer entity for const buffer.
Definition: buffers.hpp:131
restinio::impl::const_buf_t::buffer
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Definition: buffers.hpp:152
restinio::impl::const_buf_t::const_buf_t
constexpr const_buf_t(const void *data, std::size_t size) noexcept
Definition: buffers.hpp:135
restinio::impl::const_buf_t::m_data
const void *const m_data
A pointer to data.
Definition: buffers.hpp:174
restinio::impl::const_buf_t::operator=
const_buf_t & operator=(const const_buf_t &)=delete
restinio::impl::const_buf_t::relocate_to
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
Definition: buffers.hpp:157
restinio::impl::const_buf_t::size
virtual std::size_t size() const override
Get the size of a writable piece of data.
Definition: buffers.hpp:169
restinio::impl::const_buf_t::const_buf_t
const_buf_t()=delete
restinio::impl::const_buf_t::m_size
const std::size_t m_size
The size of data.
Definition: buffers.hpp:176
restinio::impl::const_buf_t::const_buf_t
const_buf_t(const const_buf_t &)=delete
restinio::impl::const_buf_t::const_buf_t
const_buf_t(const_buf_t &&)=default
restinio::impl::datasizeable_buf_t
User defined datasizable object.
Definition: buffers.hpp:189
restinio::impl::datasizeable_buf_t::datasizeable_buf_t
datasizeable_buf_t(datasizeable_buf_t &&) noexcept=default
restinio::impl::datasizeable_buf_t::relocate_to
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
Definition: buffers.hpp:231
restinio::impl::datasizeable_buf_t::datasizeable_buf_t
datasizeable_buf_t(Datasizeable buf)
Definition: buffers.hpp:212
restinio::impl::datasizeable_buf_t::buffer
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Definition: buffers.hpp:224
restinio::impl::datasizeable_buf_t::m_custom_buffer
Datasizeable m_custom_buffer
A datasizeable item that represents buffer.
Definition: buffers.hpp:248
restinio::impl::datasizeable_buf_t::size
virtual std::size_t size() const override
Get the size of a writable piece of data.
Definition: buffers.hpp:243
restinio::impl::empty_buf_t
Empty buffer entity.
Definition: buffers.hpp:92
restinio::impl::empty_buf_t::relocate_to
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
Definition: buffers.hpp:113
restinio::impl::empty_buf_t::empty_buf_t
empty_buf_t(empty_buf_t &&)=default
restinio::impl::empty_buf_t::empty_buf_t
empty_buf_t(const empty_buf_t &)=delete
restinio::impl::empty_buf_t::size
virtual std::size_t size() const override
Get the size of a writable piece of data.
Definition: buffers.hpp:125
restinio::impl::empty_buf_t::buffer
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Definition: buffers.hpp:108
restinio::impl::empty_buf_t::operator=
empty_buf_t & operator=(const empty_buf_t &)=delete
restinio::impl::empty_buf_t::empty_buf_t
empty_buf_t() noexcept
Definition: buffers.hpp:94
restinio::impl::shared_datasizeable_buf_t
Buffer based on shared_ptr of data-sizeable entity.
Definition: buffers.hpp:273
restinio::impl::shared_datasizeable_buf_t::shared_datasizeable_buf_t
shared_datasizeable_buf_t(shared_datasizeable_buf_t &&) noexcept=default
restinio::impl::shared_datasizeable_buf_t::operator=
shared_datasizeable_buf_t & operator=(const shared_datasizeable_buf_t &)=delete
restinio::impl::shared_datasizeable_buf_t::shared_datasizeable_buf_t
shared_datasizeable_buf_t(const shared_datasizeable_buf_t &)=delete
restinio::impl::shared_datasizeable_buf_t::relocate_to
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
Definition: buffers.hpp:300
restinio::impl::shared_datasizeable_buf_t::shared_ptr_t
std::shared_ptr< Datasizeable > shared_ptr_t
Definition: buffers.hpp:275
restinio::impl::shared_datasizeable_buf_t::size
virtual std::size_t size() const override
Get the size of a writable piece of data.
Definition: buffers.hpp:312
restinio::impl::shared_datasizeable_buf_t::m_buf_ptr
shared_ptr_t m_buf_ptr
A shared pointer to a datasizeable entity.
Definition: buffers.hpp:317
restinio::impl::shared_datasizeable_buf_t::shared_datasizeable_buf_t
shared_datasizeable_buf_t()=delete
restinio::impl::shared_datasizeable_buf_t::buffer
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Definition: buffers.hpp:295
restinio::impl::shared_datasizeable_buf_t::shared_datasizeable_buf_t
shared_datasizeable_buf_t(shared_ptr_t buf_ptr) noexcept
Definition: buffers.hpp:279
restinio::impl::writable_base_t
A base class for writable items.
Definition: buffers.hpp:60
restinio::impl::writable_base_t::writable_base_t
writable_base_t(const writable_base_t &)=default
restinio::impl::writable_base_t::operator=
writable_base_t & operator=(const writable_base_t &)=delete
restinio::impl::writable_base_t::writable_base_t
writable_base_t()=default
restinio::impl::writable_base_t::~writable_base_t
virtual ~writable_base_t()
Definition: buffers.hpp:68
restinio::impl::writable_base_t::size
virtual std::size_t size() const =0
Get the size of a writable piece of data.
restinio::impl::writable_base_t::writable_base_t
writable_base_t(writable_base_t &&)=default
restinio::impl::writable_base_t::relocate_to
virtual void relocate_to(void *storage)=0
Move this buffer enitity to a given location.
restinio::sendfile_t
Send file write operation description.
Definition: sendfile.hpp:226
restinio::writable_item_t
Class for storing the buffers used for streaming body (request/response).
Definition: buffers.hpp:496
restinio::writable_item_t::writable_item_t
writable_item_t(writable_item_t &&b)
Definition: buffers.hpp:556
restinio::writable_item_t::sendfile_operation
sendfile_t & sendfile_operation()
Get a reference to a sendfile operation.
Definition: buffers.hpp:604
restinio::writable_item_t::writable_item_t
writable_item_t(const writable_item_t &)=delete
restinio::writable_item_t::writable_item_t
writable_item_t(std::shared_ptr< Datasizeable > sp)
Definition: buffers.hpp:537
restinio::writable_item_t::get_writable_base
const impl::writable_base_t * get_writable_base() const noexcept
Access as writable_base_t item.
Definition: buffers.hpp:625
restinio::writable_item_t::get_sfwo
impl::sendfile_write_operation_t * get_sfwo() noexcept
Access as sendfile_write_operation_t item.
Definition: buffers.hpp:649
restinio::writable_item_t::writable_item_t
writable_item_t(const_buffer_t const_buf)
Definition: buffers.hpp:507
restinio::writable_item_t::writable_item_t
writable_item_t(Datasizeable ds)
Definition: buffers.hpp:520
restinio::writable_item_t::m_storage
storage_t m_storage
A storage for a buffer object of various types.
Definition: buffers.hpp:661
restinio::writable_item_t::~writable_item_t
~writable_item_t()
Definition: buffers.hpp:575
restinio::writable_item_t::writable_item_t
writable_item_t(const char *str)
Definition: buffers.hpp:530
restinio::writable_item_t::destroy_stored_buffer
void destroy_stored_buffer()
Definition: buffers.hpp:611
restinio::writable_item_t::m_write_type
writable_item_type_t m_write_type
Definition: buffers.hpp:617
restinio::writable_item_t::storage_t
std::aligned_storage_t< impl::needed_storage_max_size, impl::buffer_storage_align > storage_t
Definition: buffers.hpp:658
restinio::writable_item_t::buf
asio_ns::const_buffer buf() const
Create a buf reference object used by ASIO.
Definition: buffers.hpp:594
restinio::writable_item_t::get_buf
impl::buf_iface_t * get_buf() noexcept
Access as trivial buf item.
Definition: buffers.hpp:643
restinio::writable_item_t::writable_item_t
writable_item_t(sendfile_t sf_opts)
Definition: buffers.hpp:550
restinio::writable_item_t::get_writable_base
impl::writable_base_t * get_writable_base() noexcept
Access as writable_base_t item.
Definition: buffers.hpp:631
restinio::writable_item_t::operator=
writable_item_t & operator=(const writable_item_t &)=delete
restinio::writable_item_t::writable_item_t
writable_item_t()
Definition: buffers.hpp:501
restinio::writable_item_t::size
std::size_t size() const
Get the size of the underlying buffer object.
Definition: buffers.hpp:588
restinio::writable_item_t::write_type
writable_item_type_t write_type() const noexcept
Get a type of a stored buffer object.
Definition: buffers.hpp:582
restinio::writable_item_t::get_buf
const impl::buf_iface_t * get_buf() const noexcept
Access as trivial buf item.
Definition: buffers.hpp:637
restinio::write_group_t
Group of writable items transported to the context of underlying connection as one solid piece.
Definition: buffers.hpp:692
restinio::write_group_t::items
auto & items() noexcept
Get access to the stored items.
Definition: buffers.hpp:852
restinio::write_group_t::~write_group_t
~write_group_t() noexcept
Destruct object.
Definition: buffers.hpp:746
restinio::write_group_t::invoke_after_write_notificator_if_exists
void invoke_after_write_notificator_if_exists(const asio_ns::error_code &ec)
Get after write notificator.
Definition: buffers.hpp:815
restinio::write_group_t::operator=
write_group_t & operator=(const write_group_t &)=delete
restinio::write_group_t::items
const auto & items() const noexcept
Get access to the stored items.
Definition: buffers.hpp:839
restinio::write_group_t::write_group_t
write_group_t(write_group_t &&wg) noexcept
Definition: buffers.hpp:724
restinio::write_group_t::m_status_line_size
std::size_t m_status_line_size
A size of status line located in first "buffer".
Definition: buffers.hpp:903
restinio::write_group_t::status_line_size
void status_line_size(std::size_t n)
Definition: buffers.hpp:763
restinio::write_group_t::write_group_t
write_group_t(writable_items_container_t items) noexcept
Construct write group with a given bunch of writable items.
Definition: buffers.hpp:705
restinio::write_group_t::m_after_write_notificator
write_status_cb_t m_after_write_notificator
A callback to invoke once the the write opertaion of a given group completes.
Definition: buffers.hpp:906
restinio::write_group_t::m_items
writable_items_container_t m_items
A buffer objects included in this group.
Definition: buffers.hpp:896
restinio::write_group_t::after_write_notificator
void after_write_notificator(write_status_cb_t notificator) noexcept
Set after write notificator.
Definition: buffers.hpp:801
restinio::write_group_t::has_after_write_notificator
bool has_after_write_notificator() const noexcept
Is there an after write notificator set?
Definition: buffers.hpp:808
restinio::write_group_t::reset
void reset() noexcept
Reset group.
Definition: buffers.hpp:859
restinio::write_group_t::swap
friend void swap(write_group_t &left, write_group_t &right) noexcept
Swap two groups.
Definition: buffers.hpp:696
restinio::write_group_t::status_line_size
std::size_t status_line_size() const noexcept
Get status line size.
Definition: buffers.hpp:794
restinio::write_group_t::merge
void merge(write_group_t second)
Merges with another group.
Definition: buffers.hpp:881
restinio::write_group_t::items_count
auto items_count() const noexcept
Get the count of stored items.
Definition: buffers.hpp:832
restinio::write_group_t::write_group_t
write_group_t(const write_group_t &)=delete
compiler_features.hpp
Detection of compiler version and absence of various features.
RESTINIO_ENSURE_NOEXCEPT_CALL
#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr)
A wrapper around static_assert for checking that an expression is noexcept and execution of that expr...
Definition: compiler_features.hpp:60
exception.hpp
include_fmtlib.hpp
A special wrapper around fmtlib include files.
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:465
nonstd::optional_lite::swap
void swap(optional< T > &x, optional< T > &y)
Definition: optional.hpp:1705
restinio::impl::buffer_storage_align
constexpr std::size_t buffer_storage_align
Definition: buffers.hpp:378
restinio::impl::string_buf_t
datasizeable_buf_t< std::string > string_buf_t
An alias for a std::string instantiation of datasizeable_buf_t<D> template.
Definition: buffers.hpp:256
restinio::impl::needed_storage_max_size
constexpr std::size_t needed_storage_max_size
An of memory that is to be enough to hold any possible buffer entity.
Definition: buffers.hpp:388
restinio::utils::impl::uint64_to_size_t
std::size_t uint64_to_size_t(std::uint64_t v)
Helper function for truncating uint64 to std::size_t with exception if that truncation will lead to d...
Definition: safe_uint_truncate.hpp:59
restinio::utils::suppress_exceptions_quietly
void suppress_exceptions_quietly(Lambda &&lambda) noexcept
Helper function for execution a block of code with suppression of any exceptions raised inside that b...
Definition: suppress_exceptions.hpp:133
restinio
Definition: asio_include.hpp:21
restinio::writable_items_container_t
std::vector< writable_item_t > writable_items_container_t
Definition: buffers.hpp:668
restinio::const_buffer
const_buffer_t const_buffer(const char *str) noexcept
Definition: buffers.hpp:430
restinio::fmt_minimal_memory_buffer_t
fmt::basic_memory_buffer< char, 1u > fmt_minimal_memory_buffer_t
An alias for fmt::basic_memory_buffer<char,1>.
Definition: buffers.hpp:39
restinio::writable_item_type_t
writable_item_type_t
Buffers write operation type.
Definition: buffers.hpp:442
restinio::writable_item_type_t::trivial_write_operation
@ trivial_write_operation
Item is a buffer and must be written trivially.
restinio::writable_item_type_t::file_write_operation
@ file_write_operation
Item is a sendfile operation and implicates file write operation.
restinio::asio_convertible_error_t::write_group_destroyed_passively
@ write_group_destroyed_passively
After write notificator error: a notificator was set for a write_group_t but no external invokation h...
restinio::write_status_cb_t
std::function< void(const asio_ns::error_code &ec) > write_status_cb_t
An alias for a callback to be invoked after the write operation of a particular group of "buffers".
Definition: buffers.hpp:680
restinio::const_buffer
constexpr const_buffer_t const_buffer(const void *str, std::size_t size) noexcept
Definition: buffers.hpp:424
restinio::make_asio_compaible_error
asio_ns::error_code make_asio_compaible_error(asio_convertible_error_t err) noexcept
Make restinio error_code compatible with asio_ns::error_code.
Definition: asio_include.hpp:210
std
STL namespace.
safe_uint_truncate.hpp
Helpers for safe truncation of unsigned integers.
sendfile.hpp
restinio::const_buffer_t
Helper class for setting a constant buffer storage explicitly.
Definition: buffers.hpp:409
restinio::const_buffer_t::const_buffer_t
constexpr const_buffer_t(const void *str, std::size_t size) noexcept
Definition: buffers.hpp:410
restinio::const_buffer_t::m_str
const void *const m_str
Definition: buffers.hpp:417
restinio::const_buffer_t::m_size
const std::size_t m_size
Definition: buffers.hpp:418
restinio::impl::sendfile_write_operation_t
Send file operation wrapper.
Definition: buffers.hpp:326
restinio::impl::sendfile_write_operation_t::relocate_to
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
Definition: buffers.hpp:346
restinio::impl::sendfile_write_operation_t::sendfile_write_operation_t
sendfile_write_operation_t()=delete
restinio::impl::sendfile_write_operation_t::sendfile_write_operation_t
sendfile_write_operation_t(sendfile_t &&sf_opts)
Definition: buffers.hpp:330
restinio::impl::sendfile_write_operation_t::m_sendfile_options
std::unique_ptr< sendfile_t > m_sendfile_options
A pointer to sendfile operation details.
Definition: buffers.hpp:374
restinio::impl::sendfile_write_operation_t::sendfile_options
sendfile_t & sendfile_options() noexcept
Get sendfile operation detaiols.
Definition: buffers.hpp:367
restinio::impl::sendfile_write_operation_t::sendfile_write_operation_t
sendfile_write_operation_t(const sendfile_write_operation_t &)=delete
restinio::impl::sendfile_write_operation_t::operator=
sendfile_write_operation_t & operator=(const sendfile_write_operation_t &)=delete
restinio::impl::sendfile_write_operation_t::size
virtual std::size_t size() const override
Get the size of a writable piece of data.
Definition: buffers.hpp:351
restinio::impl::sendfile_write_operation_t::sendfile_write_operation_t
sendfile_write_operation_t(sendfile_write_operation_t &&)=default
suppress_exceptions.hpp
Utilities for suppressing exceptions from some code block.
const
#define const
Definition: zconf.h:230