2
3
6
7
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>
36
37
38
39
51
52
53
54
55
56
57
58
59
77 virtual std::size_t
size()
const = 0;
86
87
88 virtual asio_ns::const_buffer
buffer()
const = 0;
98 empty_buf_t &
operator = (
const empty_buf_t & ) =
delete;
101 empty_buf_t &
operator = ( empty_buf_t && ) =
delete;
104
105
106
107
109 virtual asio_ns::const_buffer
buffer()
const override
111 return asio_ns::const_buffer{
nullptr, 0 };
116 new( storage ) empty_buf_t
{};
121
122
123
124
126 virtual std::size_t
size()
const override {
return 0; }
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;
148
149
150
151
153 virtual asio_ns::const_buffer
buffer()
const override
160 new( storage ) const_buf_t{ std::move( *
this ) };
165
166
167
168
182
183
184
185
186
187
188template <
typename Datasizeable >
194 decltype( std::declval<
const Datasizeable >().data() ),
197 "Datasizeable requires 'T* data() const' member function, "
198 "where 'T*' is convertible to 'void*' " );
202 decltype( std::declval<
const Datasizeable >().size() ),
205 "Datasizeable requires 'N size() const' member function, "
206 "where 'N' is convertible to 'std::size_t'" );
209 std::is_move_constructible< Datasizeable >::value,
210 "Datasizeable must be move constructible" );
220
221
222
223
225 virtual asio_ns::const_buffer
buffer()
const override
227 return asio_ns::const_buffer{
234 new( storage ) datasizeable_buf_t{ std::move( *
this ) };
239
240
241
242
254
255
256
261
262
263
272template <
typename Datasizeable >
285 shared_datasizeable_buf_t &
operator = (
const shared_datasizeable_buf_t & ) =
delete;
288 shared_datasizeable_buf_t &
operator = ( shared_datasizeable_buf_t && ) =
delete;
291
292
293
294
296 virtual asio_ns::const_buffer
buffer()
const override
303 new( storage ) shared_datasizeable_buf_t{ std::move( *
this ) };
308
309
310
311
342
343
344
345
352 virtual std::size_t
size()
const override
354 return m_sendfile_options
355 ? ::restinio::utils::impl::uint64_to_size_t(
356 m_sendfile_options->size())
363
364
365
366
370 return *m_sendfile_options;
405
406
407
408
413 std::size_t size )
noexcept
433 return const_buffer( str, std::strlen( str ) );
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
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 };
542 typename Datasizeable,
543 typename S =
typename
553 "size of type is too big" );
555 new( m_storage.data() ) impl::datasizeable_buf_t< Datasizeable >{ std::move( ds ) };
564 template <
typename Datasizeable >
570 "size of shared_ptr on a type is too big" );
573 throw exception_t{ "empty shared_ptr cannot be used as buffer" };
575 new( m_storage.data() ) impl::shared_datasizeable_buf_t< Datasizeable >{ std::move( sp ) };
581 new( m_storage.data() ) impl::sendfile_write_operation_t{ std::move( sf_opts ) };
587 b.get_writable_base()->relocate_to( m_storage.data() );
597 b.get_writable_base()->relocate_to( m_storage.data() );
620
621
626
627
628
629
630
648
649
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() ) );
690
691
692
693
694
712
713
715 std::function<
void(
const asio_ns::error_code & ec ) >;
724
725
734 swap( left.m_items, right.m_items );
736 swap( left.m_after_write_notificator, right.m_after_write_notificator );
742 writable_items_container_t items )
noexcept
748
749
756
757
764 wg.m_after_write_notificator = write_status_cb_t{};
779
780
783 if( m_after_write_notificator )
794
795
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" };
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();
881
882
883
884
885
907 m_after_write_notificator = write_status_cb_t{};
912
913
914
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 );
935
936
937
Exception class for all exceptions thrown by RESTinio.
exception_t(const char *err)
Internal interface for a trivial buffer-like entity.
virtual asio_ns::const_buffer buffer() const =0
Get asio buf entity.
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
constexpr const_buf_t(const void *data, std::size_t size) noexcept
const void *const m_data
A pointer to data.
const_buf_t & operator=(const const_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.
const std::size_t m_size
The size of data.
const_buf_t(const const_buf_t &)=delete
const_buf_t & operator=(const_buf_t &&)=delete
const_buf_t(const_buf_t &&)=default
datasizeable_buf_t(datasizeable_buf_t &&) noexcept=default
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
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.
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.
empty_buf_t(empty_buf_t &&)=default
empty_buf_t(const empty_buf_t &)=delete
virtual std::size_t size() const override
Get the size of a writable piece of data.
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
empty_buf_t & operator=(const empty_buf_t &)=delete
empty_buf_t & operator=(empty_buf_t &&)=delete
shared_datasizeable_buf_t & operator=(shared_datasizeable_buf_t &&)=delete
shared_datasizeable_buf_t(shared_datasizeable_buf_t &&) noexcept=default
shared_datasizeable_buf_t & operator=(const shared_datasizeable_buf_t &)=delete
shared_datasizeable_buf_t(const shared_datasizeable_buf_t &)=delete
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
std::shared_ptr< Datasizeable > shared_ptr_t
virtual std::size_t size() const override
Get the size of a writable piece of data.
shared_ptr_t m_buf_ptr
A shared pointer to a datasizeable entity.
shared_datasizeable_buf_t()=delete
virtual asio_ns::const_buffer buffer() const override
Get asio buf entity.
shared_datasizeable_buf_t(shared_ptr_t buf_ptr) noexcept
A base class for writable items.
writable_base_t(const writable_base_t &)=default
writable_base_t & operator=(const writable_base_t &)=delete
writable_base_t()=default
virtual ~writable_base_t()
virtual std::size_t size() const =0
Get the size of a writable piece of data.
writable_base_t & operator=(writable_base_t &&)=delete
writable_base_t(writable_base_t &&)=default
virtual void relocate_to(void *storage)=0
Move this buffer enitity to a given location.
Send file write operation description.
Class for storing the buffers used for streaming body (request/response).
writable_item_t(writable_item_t &&b)
sendfile_t & sendfile_operation()
Get a reference to a sendfile operation.
writable_item_t(const writable_item_t &)=delete
writable_item_t(std::shared_ptr< Datasizeable > sp)
const impl::writable_base_t * get_writable_base() const noexcept
Access as writable_base_t item.
impl::sendfile_write_operation_t * get_sfwo() noexcept
Access as sendfile_write_operation_t item.
writable_item_t(const_buffer_t const_buf)
writable_item_t(Datasizeable ds)
writable_item_t(const char *str)
void destroy_stored_buffer()
writable_item_type_t m_write_type
writable_item_t & operator=(writable_item_t &&b)
asio_ns::const_buffer buf() const
Create a buf reference object used by ASIO.
impl::buf_iface_t * get_buf() noexcept
Access as trivial buf item.
writable_item_t(sendfile_t sf_opts)
impl::writable_base_t * get_writable_base() noexcept
Access as writable_base_t item.
std::array< char, impl::needed_storage_max_size > m_storage
A storage for a buffer object of various types.
writable_item_t & operator=(const writable_item_t &)=delete
std::size_t size() const
Get the size of the underlying buffer object.
writable_item_type_t write_type() const noexcept
Get a type of a stored buffer object.
const impl::buf_iface_t * get_buf() const noexcept
Access as trivial buf item.
Group of writable items transported to the context of underlying connection as one solid piece.
auto & items() noexcept
Get access to the stored items.
~write_group_t() noexcept
Destruct object.
void invoke_after_write_notificator_if_exists(const asio_ns::error_code &ec)
Get after write notificator.
write_group_t & operator=(const write_group_t &)=delete
const auto & items() const noexcept
Get access to the stored items.
write_group_t(write_group_t &&wg) noexcept
write_group_t & operator=(write_group_t &&wg) noexcept
std::size_t m_status_line_size
A size of status line located in first "buffer".
void status_line_size(std::size_t n)
write_group_t(writable_items_container_t items) noexcept
Construct write group with a given bunch of writable items.
write_status_cb_t m_after_write_notificator
A callback to invoke once the the write opertaion of a given group completes.
writable_items_container_t m_items
A buffer objects included in this group.
void after_write_notificator(write_status_cb_t notificator) noexcept
Set after write notificator.
bool has_after_write_notificator() const noexcept
Is there an after write notificator set?
void reset() noexcept
Reset group.
friend void swap(write_group_t &left, write_group_t &right) noexcept
Swap two groups.
std::size_t status_line_size() const noexcept
Get status line size.
void merge(write_group_t second)
Merges with another group.
auto items_count() const noexcept
Get the count of stored items.
write_group_t(const write_group_t &)=delete
#define RESTINIO_ENSURE_NOEXCEPT_CALL(expr)
A wrapper around static_assert for checking that an expression is noexcept and execution of that expr...
constexpr std::size_t buffer_storage_align
datasizeable_buf_t< std::string > string_buf_t
An alias for a std::string instantiation of datasizeable_buf_t<D> template.
constexpr std::size_t needed_storage_max_size
An of memory that is to be enough to hold any possible buffer entity.
const_buffer_t const_buffer(const char *str) noexcept
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".
writable_item_type_t
Buffers write operation type.
@ trivial_write_operation
Item is a buffer and must be written trivially.
@ file_write_operation
Item is a sendfile operation and implicates file write operation.
asio_convertible_error_t
Enum for restinio errors that must presented as asio_ns::error_code value.
@ write_group_destroyed_passively
After write notificator error: a notificator was set for a write_group_t but no external invokation h...
constexpr const_buffer_t const_buffer(const void *str, std::size_t size) noexcept
asio_ns::error_code make_asio_compaible_error(asio_convertible_error_t err) noexcept
Make restinio error_code compatible with asio_ns::error_code.
Helper class for setting a constant buffer storage explicitly.
constexpr const_buffer_t(const void *str, std::size_t size) noexcept
Send file operation wrapper.
virtual void relocate_to(void *storage) override
Move this buffer enitity to a given location.
sendfile_write_operation_t()=delete
sendfile_write_operation_t(sendfile_t &&sf_opts)
std::unique_ptr< sendfile_t > m_sendfile_options
A pointer to sendfile operation details.
sendfile_t & sendfile_options() noexcept
Get sendfile operation detaiols.
sendfile_write_operation_t(const sendfile_write_operation_t &)=delete
sendfile_write_operation_t & operator=(const sendfile_write_operation_t &)=delete
virtual std::size_t size() const override
Get the size of a writable piece of data.
sendfile_write_operation_t & operator=(sendfile_write_operation_t &&)=delete
sendfile_write_operation_t(sendfile_write_operation_t &&)=default