16 #include <type_traits> 18 #include <restinio/asio_include.hpp> 19 #include <restinio/exception.hpp> 20 #include <restinio/sendfile.hpp> 22 #include <restinio/compiler_features.hpp> 23 #include <restinio/utils/suppress_exceptions.hpp> 24 #include <restinio/utils/impl/safe_uint_truncate.hpp> 26 #include <restinio/impl/include_fmtlib.hpp> 98 empty_buf_t &
operator = (
const empty_buf_t & ) =
delete;
101 empty_buf_t &
operator = ( empty_buf_t && ) =
delete;
111 return asio_ns::const_buffer{
nullptr, 0 };
116 new( storage ) empty_buf_t{};
136 constexpr const_buf_t(
const void * data, std::size_t size )
noexcept 142 const_buf_t &
operator = (
const const_buf_t & ) =
delete;
145 const_buf_t &
operator = ( const_buf_t && ) =
delete;
155 return asio_ns::const_buffer{ m_data, m_size };
160 new( storage ) const_buf_t{ std::move( *
this ) };
188 template <
typename Datasizeable >
197 "Datasizeable requires 'T* data() const' member function, " 198 "where 'T*' is convertible to 'void*' " );
205 "Datasizeable requires 'N size() const' member function, " 206 "where 'N' is convertible to 'std::size_t'" );
210 "Datasizeable must be move constructible" );
272 template <
typename Datasizeable >
349 new( storage ) sendfile_write_operation_t{ std::move( *
this ) };
354 return m_sendfile_options
355 ? ::restinio::utils::impl::uint64_to_size_t(
356 m_sendfile_options->size())
370 return *m_sendfile_options;
413 std::size_t size )
noexcept 427 return const_buffer_t{ str, size };
433 return const_buffer( str, std::strlen( str ) );
532 new( m_storage.data() ) impl::empty_buf_t{};
538 new( m_storage.data() ) impl::const_buf_t{ const_buf.m_str, const_buf.m_size };
543 typename S =
typename 553 "size of type is too big" );
570 "size of shared_ptr on a type is too big" );
573 throw exception_t{
"empty shared_ptr cannot be used as buffer" };
656 reinterpret_cast<
const impl::writable_base_t * >( m_storage.data() ) );
663 reinterpret_cast< impl::writable_base_t * >( m_storage.data() ) );
670 reinterpret_cast<
const impl::buf_iface_t * >( m_storage.data() ) );
677 reinterpret_cast< impl::buf_iface_t * >( m_storage.data() ) );
684 reinterpret_cast< impl::sendfile_write_operation_t * >( m_storage.data() ) );
734 swap( left.m_items, right.m_items );
735 swap( left.m_status_line_size, right.m_status_line_size );
736 swap( left.m_after_write_notificator, right.m_after_write_notificator );
742 writable_items_container_t items )
noexcept 764 wg.m_after_write_notificator = write_status_cb_t{};
765 wg.m_status_line_size = 0;
783 if( m_after_write_notificator )
785 restinio::utils::suppress_exceptions_quietly( [&] {
786 invoke_after_write_notificator_if_exists(
787 make_asio_compaible_error(
788 asio_convertible_error_t::write_group_destroyed_passively ) );
800 if( std::size_t{0} != n )
802 if( m_items.empty() )
805 "cannot set status line size for empty write group" };
808 if( writable_item_type_t::trivial_write_operation !=
809 m_items.front().write_type() )
812 "cannot set status line size for write group: " 813 "first writable item must be 'trivial_write_operation'" };
816 if( m_items.front().size() < n )
819 "cannot set status line size for write group: " 820 "first writable item size is less than provided value" };
823 m_status_line_size = n;
831 return m_status_line_size;
838 m_after_write_notificator = std::move( notificator );
845 return static_cast<
bool >( m_after_write_notificator );
852 if( m_after_write_notificator )
854 auto tmp = std::move( m_after_write_notificator );
858 m_after_write_notificator = write_status_cb_t{};
869 return m_items.size();
897 RESTINIO_ENSURE_NOEXCEPT_CALL( m_items.clear() );
898 m_status_line_size = 0;
907 m_after_write_notificator = write_status_cb_t{};
918 auto & second_items = second.m_items;
919 m_items.reserve( m_items.size() + second_items.size() );
922 begin( second_items ),
924 std::back_inserter( m_items ) );
926 m_after_write_notificator = std::move( second.m_after_write_notificator );
const_buf_t(const const_buf_t &)=delete
write_group_t & operator=(write_group_t &&wg) noexcept
const impl::buf_iface_t * get_buf() const noexcept
Access as trivial buf item.
Item is a sendfile operation and implicates file write operation.
write_status_cb_t m_after_write_notificator
A callback to invoke once the the write opertaion of a given group completes.
A base class for writable items.
Send file operation wrapper.
shared_datasizeable_buf_t & operator=(const shared_datasizeable_buf_t &)=delete
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
virtual std::size_t size() const override
Get the size of a writable piece of data.
std::array< char, impl::needed_storage_max_size > m_storage
A storage for a buffer object of various types.
sendfile_write_operation_t & operator=(const sendfile_write_operation_t &)=delete
constexpr const_buffer_t const_buffer(const void *str, std::size_t size) noexcept
sendfile_write_operation_t(sendfile_t &&sf_opts)
writable_items_container_t m_items
A buffer objects included in this group.
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
writable_item_type_t
Buffers write operation type.
writable_base_t(writable_base_t &&)=default
bool has_after_write_notificator() const noexcept
Is there an after write notificator set?
~write_group_t() noexcept
Destruct object.
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
empty_buf_t(const empty_buf_t &)=delete
const_buffer_t const_buffer(const char *str) noexcept
Item is a buffer and must be written trivially.
const_buf_t & operator=(const const_buf_t &)=delete
empty_buf_t(empty_buf_t &&)=default
const_buf_t(const_buf_t &&)=default
virtual std::size_t size() const override
Get the size of a writable piece of data.
constexpr const_buffer_t(const void *str, std::size_t size) noexcept
impl::buf_iface_t * get_buf() noexcept
Access as trivial buf item.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
virtual void relocate_to(void *storage)=0
Move this buffer enitity to a given location.
void merge(write_group_t second)
Merges with another group.
void after_write_notificator(write_status_cb_t notificator) noexcept
Set after write notificator.
write_group_t(const write_group_t &)=delete
Helper class for setting a constant buffer storage explicitly.
empty_buf_t & operator=(const empty_buf_t &)=delete
writable_base_t()=default
virtual std::size_t size() const override
Get the size of a writable piece of data.
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
std::size_t status_line_size() const noexcept
Get status line size.
constexpr std::size_t needed_storage_max_size
An of memory that is to be enough to hold any possible buffer entity.
auto items_count() const noexcept
Get the count of stored items.
const impl::writable_base_t * get_writable_base() const noexcept
Access as writable_base_t item.
auto & items() noexcept
Get access to the stored items.
Internal interface for a trivial buffer-like entity.
writable_base_t(const writable_base_t &)=default
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
virtual std::size_t size() const override
Get the size of a writable piece of data.
writable_item_t & operator=(const writable_item_t &)=delete
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
std::unique_ptr< sendfile_t > m_sendfile_options
A pointer to sendfile operation details.
writable_item_t(const_buffer_t const_buf)
impl::sendfile_write_operation_t * get_sfwo() noexcept
Access as sendfile_write_operation_t item.
const auto & items() const noexcept
Get access to the stored items.
writable_base_t & operator=(const writable_base_t &)=delete
empty_buf_t & operator=(empty_buf_t &&)=delete
virtual ~writable_base_t()
write_group_t(writable_items_container_t items) noexcept
Construct write group with a given bunch of writable items.
void invoke_after_write_notificator_if_exists(const asio_ns::error_code &ec)
Get after write notificator.
Group of writable items transported to the context of underlying connection as one solid piece...
impl::writable_base_t * get_writable_base() noexcept
Access as writable_base_t item.
shared_datasizeable_buf_t & operator=(shared_datasizeable_buf_t &&)=delete
datasizeable_buf_t(datasizeable_buf_t &&) noexcept=default
sendfile_t & sendfile_options() noexcept
Get sendfile operation detaiols.
write_group_t(write_group_t &&wg) noexcept
sendfile_write_operation_t()=delete
void status_line_size(std::size_t n)
shared_datasizeable_buf_t(shared_datasizeable_buf_t &&) noexcept=default
virtual std::size_t size() const override
Get the size of a writable piece of data.
friend void swap(write_group_t &left, write_group_t &right) noexcept
Swap two groups.
const void *const m_data
A pointer to data.
const_buf_t & operator=(const_buf_t &&)=delete
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
sendfile_write_operation_t(const sendfile_write_operation_t &)=delete
void reset() noexcept
Reset group.
const std::size_t m_size
The size of data.
sendfile_write_operation_t(sendfile_write_operation_t &&)=default
shared_datasizeable_buf_t()=delete
writable_base_t & operator=(writable_base_t &&)=delete
constexpr std::size_t buffer_storage_align
datasizeable_buf_t(Datasizeable buf)
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Datasizeable m_custom_buffer
A datasizeable item that represents buffer.
write_group_t & operator=(const write_group_t &)=delete
sendfile_write_operation_t & operator=(sendfile_write_operation_t &&)=delete
shared_ptr_t m_buf_ptr
A shared pointer to a datasizeable entity.
writable_item_t(const writable_item_t &)=delete
virtual std::size_t size() const =0
Get the size of a writable piece of data.
virtual asio_ns::const_buffer buffer() const =0
Get asio buf entity.
shared_datasizeable_buf_t(shared_ptr_t buf_ptr) noexcept
shared_datasizeable_buf_t(const shared_datasizeable_buf_t &)=delete
User defined datasizable object.
constexpr const_buf_t(const void *data, std::size_t size) noexcept
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
Buffer based on shared_ptr of data-sizeable entity.
void destroy_stored_buffer()
std::size_t m_status_line_size
A size of status line located in first "buffer".