RESTinio
Loading...
Searching...
No Matches
settings.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
12
15#include <restinio/traits.hpp>
16
18
19#include <chrono>
20#include <variant>
21#include <tuple>
22#include <utility>
23
24namespace restinio
25{
26
27namespace details
28{
29
31template < typename Object >
32inline auto
34{
35 return std::unique_ptr< Object >{};
36}
37
38template < typename Object >
39inline auto
41{
42 return std::make_unique< Object >();
43}
44
46template < typename Object >
47inline auto
49{
50 return std::shared_ptr< Object >{};
51}
52
53template < typename Object >
54inline auto
56{
57 return std::make_shared< Object >();
58}
59
60} /* namespace details */
61
62//
63// create_default_unique_object_instance
64//
65
67template < typename Object>
68inline auto
70{
71 typename std::is_default_constructible< Object >::type tag;
72 return details::create_default_unique_object_instance< Object >( tag );
73}
74
76template <>
77inline auto
79{
80 return details::create_default_unique_object_instance< default_request_handler_t >(
81 std::false_type{} );
82}
83
84//
85// create_default_shared_object_instance
86//
87
89template < typename Object>
90inline auto
92{
93 typename std::is_default_constructible< Object >::type tag;
94 return details::create_default_shared_object_instance< Object >( tag );
95}
96
98template <>
99inline auto
101{
102 return details::create_default_shared_object_instance< default_request_handler_t >(
103 std::false_type{} );
104}
105
106//
107// ensure_created()
108//
109
111template < typename Object >
112auto
125
126//
127// unsure_created()
128//
129
131template < typename Object >
132auto
145
146
147//
148// socket_type_dependent_settings_t
149//
150
152template < typename Settings, typename Socket >
172
173//
174// acceptor_options_t
175//
176
178
184{
185 public:
186 acceptor_options_t( asio_ns::ip::tcp::acceptor & acceptor )
187 : m_acceptor{ acceptor }
188 {}
189
192 template< typename Option >
193 void
195 {
196 m_acceptor.set_option( option );
197 }
198
199 template< typename Option >
200 void
201 set_option( const Option & option, asio_ns::error_code & ec )
202 {
203 m_acceptor.set_option( option, ec );
204 }
205
206 template< typename Option >
207 void
209 {
210 m_acceptor.get_option( option );
211 }
212
213 template< typename Option >
214 void
215 get_option( Option & option, asio_ns::error_code & ec )
216 {
217 m_acceptor.get_option( option, ec );
218 }
220
221 private:
222 asio_ns::ip::tcp::acceptor & m_acceptor;
223};
224
225using acceptor_options_setter_t = std::function< void ( acceptor_options_t & ) >;
226
227template <>
228inline auto
230{
231 return std::make_unique< acceptor_options_setter_t >(
233 options.set_option( asio_ns::ip::tcp::acceptor::reuse_address( true ) );
234 } );
235}
236
237//
238// socket_options_t
239//
240
242
248{
249 public:
252 asio_ns::basic_socket< asio_ns::ip::tcp > & socket )
253 : m_socket{ socket }
254 {}
255
258 template< typename Option >
259 void
260 set_option( const Option & option )
261 {
262 m_socket.set_option( option );
263 }
264
265 template< typename Option >
266 void
267 set_option( const Option & option, asio_ns::error_code & ec )
268 {
269 m_socket.set_option( option, ec );
270 }
271
272 template< typename Option >
273 void
274 get_option( Option & option )
275 {
276 m_socket.get_option( option );
277 }
278
279 template< typename Option >
280 void
281 get_option( Option & option, asio_ns::error_code & ec )
282 {
283 m_socket.get_option( option, ec );
284 }
286
287 private:
289 asio_ns::basic_socket< asio_ns::ip::tcp > & m_socket;
290};
291
292using socket_options_setter_t = std::function< void ( socket_options_t & ) >;
293
294template <>
295inline auto
297{
298 return std::make_unique< socket_options_setter_t >( []( auto & ){} );
299}
300
301//
302// cleanup_functor_t
303//
307using cleanup_functor_t = std::function< void(void) >;
308
309//
310// connection_state_listener_holder_t
311//
321template< typename Listener >
323{
324 std::shared_ptr< Listener > m_connection_state_listener;
325
326 static constexpr bool has_actual_connection_state_listener = true;
327
329
332 void
334 {
335 if( !m_connection_state_listener )
336 throw exception_t{ "connection state listener is not specified" };
337 }
338};
339
348template<>
349struct connection_state_listener_holder_t< connection_state::noop_listener_t >
350{
351 static constexpr bool has_actual_connection_state_listener = false;
352
353 void
355 {
356 // Nothing to do.
357 }
358};
359
360//
361// ip_blocker_holder_t
362//
372template< typename Ip_Blocker >
374{
375 static_assert(
376 noexcept( std::declval<Ip_Blocker>().inspect(
377 std::declval<ip_blocker::incoming_info_t>() ) ),
378 "Ip_Blocker::inspect() method should be noexcept" );
379
380 static_assert(
381 std::is_same<
383 decltype(std::declval<Ip_Blocker>().inspect(
384 std::declval<ip_blocker::incoming_info_t>())) >::value,
385 "Ip_Blocker::inspect() should return "
386 "restinio::ip_blocker::inspection_result_t" );
387
388 std::shared_ptr< Ip_Blocker > m_ip_blocker;
389
390 static constexpr bool has_actual_ip_blocker = true;
391
393
396 void
398 {
399 if( !m_ip_blocker )
400 throw exception_t{ "IP-blocker is not specified" };
401 }
402};
403
412template<>
413struct ip_blocker_holder_t< ip_blocker::noop_ip_blocker_t >
414{
415 static constexpr bool has_actual_ip_blocker = false;
416
417 void
419 {
420 // Nothing to do.
421 }
422};
423
424//
425// acceptor_post_bind_hook_t
426//
433using acceptor_post_bind_hook_t = std::function<
434 void(asio_ns::ip::tcp::acceptor &) >;
435
436namespace details
437{
438
439//
440// no_address_specified_t
441//
449
450//
451// address_variant_t
452//
459using address_variant_t = std::variant<
461 std::string,
462 asio_ns::ip::address >;
463
464//
465// max_parallel_connections_holder_t
466//
479template< typename Count_Limiter >
481{
482 static constexpr bool has_actual_max_parallel_connections = true;
483
489 std::size_t m_max_parallel_connections{
490 std::numeric_limits<std::size_t>::max()
491 };
492
493 std::size_t
495 {
496 return m_max_parallel_connections;
497 }
498
499 void
500 set_max_parallel_connections( std::size_t v ) noexcept
501 {
502 m_max_parallel_connections = v;
503 }
504};
505
517template<>
520{
521 static constexpr bool has_actual_max_parallel_connections = false;
522
523 std::size_t
525 {
526 return std::numeric_limits<std::size_t>::max();
527 }
528};
529
530} /* namespace details */
531
532//
533// basic_server_settings_t
534//
535
537
547template<typename Derived, typename Traits>
549 : public socket_type_dependent_settings_t< Derived, typename Traits::stream_socket_t >
551 typename Traits::connection_state_listener_t >
552 , protected ip_blocker_holder_t< typename Traits::ip_blocker_t >
554 typename connection_count_limit_types<Traits>::limiter_t >
555{
557 Derived, typename Traits::stream_socket_t>;
558
562
564 typename Traits::connection_state_listener_t
565 >::has_actual_connection_state_listener;
566
568 typename Traits::ip_blocker_t
569 >::has_actual_ip_blocker;
570
571 using max_parallel_connections_holder_base_t::has_actual_max_parallel_connections;
572
573 public:
575 std::uint16_t port = 8080,
576 asio_ns::ip::tcp protocol = asio_ns::ip::tcp::v4() )
577 : base_type_t{}
578 , m_port{ port }
579 , m_protocol{ protocol }
580 {}
581
584 Derived &
585 port( std::uint16_t p ) &
586 {
587 m_port = p;
588 return reference_to_derived();
589 }
590
591 Derived &&
592 port( std::uint16_t p ) &&
593 {
594 return std::move( this->port( p ) );
595 }
596
597 [[nodiscard]]
598 std::uint16_t
599 port() const
600 {
601 return m_port;
602 }
603
604 Derived &
605 protocol( asio_ns::ip::tcp p ) &
606 {
607 m_protocol = p;
608 return reference_to_derived();
609 }
610
611 Derived &&
612 protocol( asio_ns::ip::tcp p ) &&
613 {
614 return std::move( this->protocol( p ) );
615 }
616
617 [[nodiscard]]
618 asio_ns::ip::tcp
619 protocol() const
620 {
621 return m_protocol;
622 }
623
641 Derived &
642 address( std::string addr ) &
643 {
644 m_address = std::move(addr);
645 return reference_to_derived();
646 }
647
661 Derived &&
662 address( std::string addr ) &&
663 {
664 return std::move( this->address( std::move( addr ) ) );
665 }
666
686 Derived &
687 address( asio_ns::ip::address addr ) &
688 {
689 m_address = addr;
690 return reference_to_derived();
691 }
692
708 Derived &&
709 address( asio_ns::ip::address addr ) &&
710 {
711 return std::move( this->address( addr ) );
712 }
713
714 [[nodiscard]]
716 address() const
717 {
718 return m_address;
719 }
721
723
728 Derived &
729 buffer_size( std::size_t s ) &
730 {
731 m_buffer_size = s;
732 return reference_to_derived();
733 }
734
735 Derived &&
736 buffer_size( std::size_t s ) &&
737 {
738 return std::move( this->buffer_size( s ) );
739 }
740
741 std::size_t
743 {
744 return m_buffer_size;
745 }
747
751
755 Derived &
756 read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &
757 {
758 m_read_next_http_message_timelimit = std::move( d );
759 return reference_to_derived();
760 }
761
762 Derived &&
763 read_next_http_message_timelimit( std::chrono::steady_clock::duration d ) &&
764 {
765 return std::move( this->read_next_http_message_timelimit( std::move( d ) ) );
766 }
767
768 std::chrono::steady_clock::duration
770 {
771 return m_read_next_http_message_timelimit;
772 }
774
777 Derived &
778 write_http_response_timelimit( std::chrono::steady_clock::duration d ) &
779 {
780 m_write_http_response_timelimit = std::move( d );
781 return reference_to_derived();
782 }
783
784 Derived &&
785 write_http_response_timelimit( std::chrono::steady_clock::duration d ) &&
786 {
787 return std::move( this->write_http_response_timelimit( std::move( d ) ) );
788 }
789
790 std::chrono::steady_clock::duration
792 {
793 return m_write_http_response_timelimit;
794 }
796
799 Derived &
800 handle_request_timeout( std::chrono::steady_clock::duration d ) &
801 {
802 m_handle_request_timeout = std::move( d );
803 return reference_to_derived();
804 }
805
806 Derived &&
807 handle_request_timeout( std::chrono::steady_clock::duration d ) &&
808 {
809 return std::move( this->handle_request_timeout( std::move( d ) ) );
810 }
811
812 std::chrono::steady_clock::duration
814 {
815 return m_handle_request_timeout;
816 }
818
821 Derived &
822 max_pipelined_requests( std::size_t mpr ) &
823 {
824 m_max_pipelined_requests = mpr;
825 return reference_to_derived();
826 }
827
828 Derived &&
829 max_pipelined_requests( std::size_t mpr ) &&
830 {
831 return std::move( this->max_pipelined_requests( mpr ) );
832 }
833
834 std::size_t
836 {
837 return m_max_pipelined_requests;
838 }
840
841
845
846 Derived &
847 request_handler( std::unique_ptr< request_handler_t > handler ) &
848 {
849 m_request_handler = std::move( handler );
850 return reference_to_derived();
851 }
852
853 template< typename... Params >
854 Derived &
855 request_handler( Params &&... params ) &
856 {
857 return set_unique_instance(
858 m_request_handler,
859 std::forward< Params >( params )... );
860 }
861
862
863 template< typename... Params >
864 Derived &&
865 request_handler( Params &&... params ) &&
866 {
867 return std::move( this->request_handler( std::forward< Params >( params )... ) );
868 }
869
870 std::unique_ptr< request_handler_t >
872 {
873 return ensure_created(
874 std::move( m_request_handler ),
875 "request handler must be set" );
876 }
878
879
882
885 using timer_manager_t = typename Traits::timer_manager_t;
890 using timer_factory_t = typename timer_manager_t::factory_t;
891
916 template< typename... Params >
917 Derived &
918 timer_manager( Params &&... params ) &
919 {
920 return set_unique_instance(
921 m_timer_factory,
922 std::forward< Params >( params )... );
923 }
924
932 template< typename... Params >
933 Derived &&
934 timer_manager( Params &&... params ) &&
935 {
936 return std::move( this->timer_manager( std::forward< Params >( params )... ) );
937 }
938
939 std::unique_ptr< timer_factory_t >
941 {
942 return ensure_created(
943 std::move( m_timer_factory ),
944 "timer manager is not set" );
945 }
947
950 using logger_t = typename Traits::logger_t;
951
952 template< typename... Params >
953 Derived &
954 logger( Params &&... params ) &
955 {
956 return set_unique_instance(
957 m_logger,
958 std::forward< Params >( params )... );
959 }
960
961 template< typename... Params >
962 Derived &&
963 logger( Params &&... params ) &&
964 {
965 return std::move( this->logger( std::forward< Params >( params )... ) );
966 }
967
968 std::unique_ptr< logger_t >
970 {
971 return ensure_created(
972 std::move( m_logger ),
973 "logger must be set" );
974 }
976
979 Derived &
981 {
982 if( !aos )
983 throw exception_t{ "acceptor options setter cannot be empty" };
984
985 return set_unique_instance(
986 m_acceptor_options_setter,
987 std::move( aos ) );
988 }
989
990 Derived &&
992 {
993 return std::move( this->acceptor_options_setter( std::move( aos ) ) );
994 }
995
996 std::unique_ptr< acceptor_options_setter_t >
998 {
999 return ensure_created(
1000 std::move( m_acceptor_options_setter ),
1001 "acceptor options setter must be set" );
1002 }
1004
1007 Derived &
1009 {
1010 if( !sos )
1011 throw exception_t{ "socket options setter cannot be empty" };
1012
1013 return set_unique_instance(
1014 m_socket_options_setter,
1015 std::move( sos ) );
1016 }
1017
1018 Derived &&
1020 {
1021 return std::move( this->socket_options_setter( std::move( sos ) ) );
1022 }
1023
1024 std::unique_ptr< socket_options_setter_t >
1026 {
1027 return ensure_created(
1028 std::move( m_socket_options_setter ),
1029 "socket options setter must be set" );
1030 }
1032
1034
1039 Derived &
1040 concurrent_accepts_count( std::size_t n ) &
1041 {
1042 if( 0 == n || 1024 < n )
1043 throw exception_t{
1044 fmt::format(
1046 "invalid value for number of cuncurrent connects: {}" ),
1047 n ) };
1048
1049 m_concurrent_accepts_count = n;
1050 return reference_to_derived();
1051 }
1052
1053 Derived &&
1054 concurrent_accepts_count( std::size_t n ) &&
1055 {
1056 return std::move( this->concurrent_accepts_count( n ) );
1057 }
1058
1059 std::size_t
1061 {
1062 return m_concurrent_accepts_count;
1063 }
1065
1067
1076 Derived &
1077 separate_accept_and_create_connect( bool do_separate ) & noexcept
1078 {
1079 m_separate_accept_and_create_connect = do_separate;
1080 return reference_to_derived();
1081 }
1082
1083 Derived &&
1084 separate_accept_and_create_connect( bool do_separate ) && noexcept
1085 {
1086 return std::move( this->separate_accept_and_create_connect( do_separate ) );
1087 }
1088
1089 bool
1091 {
1092 return m_separate_accept_and_create_connect;
1093 }
1095
1098 template< typename Func >
1099 Derived &
1100 cleanup_func( Func && func ) &
1101 {
1102 m_cleanup_functor = std::move(func);
1103 return reference_to_derived();
1104 }
1105
1106 template< typename Func >
1107 Derived &&
1108 cleanup_func( Func && func ) &&
1109 {
1110 return std::move(this->cleanup_func( std::forward<Func>(func) ));
1111 }
1112
1119 [[nodiscard]]
1122 {
1123 return std::move(m_cleanup_functor);
1124 }
1126
1157 Derived &
1159 std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &
1160 {
1161 static_assert(
1162 has_actual_connection_state_listener,
1163 "connection_state_listener(listener) can't be used "
1164 "for the default connection_state::noop_listener_t" );
1165
1166 this->m_connection_state_listener = std::move(listener);
1167 return reference_to_derived();
1168 }
1169
1201 Derived &&
1203 std::shared_ptr< typename Traits::connection_state_listener_t > listener ) &&
1204 {
1205 return std::move(this->connection_state_listener(
1206 std::move(listener)));
1207 }
1208
1217 const std::shared_ptr< typename Traits::connection_state_listener_t > &
1219 {
1220 static_assert(
1221 has_actual_connection_state_listener,
1222 "connection_state_listener() can't be used "
1223 "for the default connection_state::noop_listener_t" );
1224
1225 return this->m_connection_state_listener;
1226 }
1227
1237 void
1239 {
1240 this->check_valid_connection_state_listener_pointer();
1241 }
1242
1274 Derived &
1276 std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &
1277 {
1278 static_assert(
1279 basic_server_settings_t::has_actual_ip_blocker,
1280 "ip_blocker(blocker) can't be used "
1281 "for the default ip_blocker::noop_ip_blocker_t" );
1282
1283 this->m_ip_blocker = std::move(blocker);
1284 return reference_to_derived();
1285 }
1286
1319 Derived &&
1321 std::shared_ptr< typename Traits::ip_blocker_t > blocker ) &&
1322 {
1323 return std::move(this->ip_blocker(std::move(blocker)));
1324 }
1325
1334 const std::shared_ptr< typename Traits::ip_blocker_t > &
1335 ip_blocker() const noexcept
1336 {
1337 static_assert(
1338 basic_server_settings_t::has_actual_ip_blocker,
1339 "ip_blocker() can't be used "
1340 "for the default ip_blocker::noop_ip_blocker_t" );
1341
1342 return this->m_ip_blocker;
1343 }
1344
1353 void
1355 {
1356 this->check_valid_ip_blocker_pointer();
1357 }
1358
1359 // Acceptor post-bind hook.
1383 Derived &
1385 {
1386 if( !hook )
1387 throw exception_t{ "acceptor_post_bind_hook cannot be empty" };
1388
1389 m_acceptor_post_bind_hook = std::move(hook);
1390 return reference_to_derived();
1391 }
1392
1412 Derived &&
1414 {
1415 return std::move(this->acceptor_post_bind_hook( std::move(hook) ));
1416 }
1417
1428 [[nodiscard]]
1431 {
1432 return std::move(m_acceptor_post_bind_hook);
1433 }
1434
1448 [[nodiscard]]
1451 {
1452 return m_incoming_http_msg_limits;
1453 }
1454
1477 Derived &
1479 const incoming_http_msg_limits_t & limits ) & noexcept
1480 {
1481 m_incoming_http_msg_limits = limits;
1482 return reference_to_derived();
1483 }
1484
1507 Derived &&
1509 const incoming_http_msg_limits_t & limits ) && noexcept
1510 {
1511 return std::move(this->incoming_http_msg_limits(limits));
1512 }
1513
1538 Derived &
1539 max_parallel_connections( std::size_t value ) & noexcept
1540 {
1541 static_assert(
1542 basic_server_settings_t::has_actual_max_parallel_connections,
1543 "max_parallel_connections(value) can't be used "
1544 "for the noop_connection_count_limiter_t" );
1545
1546 this->set_max_parallel_connections( value );
1547 return reference_to_derived();
1548 }
1549
1573 Derived &&
1574 max_parallel_connections( std::size_t value ) && noexcept
1575 {
1576 return std::move(this->max_parallel_connections( value ));
1577 }
1578
1579 using max_parallel_connections_holder_base_t::max_parallel_connections;
1580
1589 using extra_data_factory_t = typename Traits::extra_data_factory_t;
1594 using extra_data_factory_handle_t = std::shared_ptr< extra_data_factory_t >;
1595
1629 Derived &
1631 extra_data_factory_handle_t factory ) &
1632 {
1633 this->m_extra_data_factory = std::move(factory);
1634 return reference_to_derived();
1635 }
1636
1669 Derived &&
1671 extra_data_factory_handle_t factory ) &&
1672 {
1673 return std::move(this->extra_data_factory( std::move(factory) ));
1674 }
1675
1680 [[nodiscard]]
1681 extra_data_factory_handle_t
1683 {
1684 return ensure_created(
1685 std::move(this->m_extra_data_factory),
1686 "extra_data_factory is not set" );
1687 }
1692 private:
1693 Derived &
1695 {
1696 return static_cast<Derived &>(*this);
1697 }
1698
1699 template< typename Target, typename... Params >
1700 Derived &
1701 set_unique_instance( std::unique_ptr< Target > & t, Params &&... params )
1702 {
1703 t =
1704 std::make_unique< Target >(
1705 std::forward< Params >( params )... );
1706
1707 return reference_to_derived();
1708 }
1709
1710 template< typename Target, typename... Params >
1711 Derived &
1712 set_shared_instance( std::shared_ptr< Target > & t, Params &&... params )
1713 {
1714 t =
1715 std::make_shared< Target >(
1716 std::forward< Params >( params )... );
1717
1718 return reference_to_derived();
1719 }
1720
1723 std::uint16_t m_port;
1724 asio_ns::ip::tcp m_protocol;
1731
1733 std::size_t m_buffer_size{ 4 * 1024 };
1734
1737 std::chrono::steady_clock::duration
1738 m_read_next_http_message_timelimit{ std::chrono::seconds( 60 ) };
1739
1740 std::chrono::steady_clock::duration
1741 m_write_http_response_timelimit{ std::chrono::seconds( 5 ) };
1742
1743 std::chrono::steady_clock::duration
1744 m_handle_request_timeout{ std::chrono::seconds( 10 ) };
1746
1748 std::size_t m_max_pipelined_requests{ 1 };
1749
1751 std::unique_ptr< request_handler_t > m_request_handler;
1752
1754 std::unique_ptr< timer_factory_t > m_timer_factory;
1755
1757 std::unique_ptr< logger_t > m_logger;
1758
1760 std::unique_ptr< acceptor_options_setter_t > m_acceptor_options_setter;
1761
1763
1768 acceptor_post_bind_hook_t m_acceptor_post_bind_hook{
1769 [](asio_ns::ip::tcp::acceptor &) {}
1770 };
1771
1773 std::unique_ptr< socket_options_setter_t > m_socket_options_setter;
1774
1775 std::size_t m_concurrent_accepts_count{ 1 };
1776
1778 bool m_separate_accept_and_create_connect{ false };
1779
1782
1789
1796};
1797
1798//
1799// server_settings_t
1800//
1801
1803template<typename Traits = default_traits_t>
1805 : public basic_server_settings_t< server_settings_t<Traits>, Traits >
1806{
1809public:
1811};
1812
1813template < typename Traits, typename Configurator >
1814auto
1823
1824} /* namespace restinio */
1825
An adapter for setting acceptor options before running server.
Definition settings.hpp:184
void set_option(const Option &option, asio_ns::error_code &ec)
Definition settings.hpp:201
void set_option(const Option &option)
API for setting/getting options.
Definition settings.hpp:194
void get_option(Option &option, asio_ns::error_code &ec)
Definition settings.hpp:215
void get_option(Option &option)
Definition settings.hpp:208
asio_ns::ip::tcp::acceptor & m_acceptor
Definition settings.hpp:222
acceptor_options_t(asio_ns::ip::tcp::acceptor &acceptor)
Definition settings.hpp:186
Basic container for http_server settings.
Definition settings.hpp:555
typename timer_manager_t::factory_t timer_factory_t
Short alias for type of a factory that creates instances of timer_manager.
Definition settings.hpp:890
const std::shared_ptr< typename Traits::ip_blocker_t > & ip_blocker() const noexcept
Get reference to IP-blocker.
std::unique_ptr< request_handler_t > m_request_handler
Request handler.
std::unique_ptr< acceptor_options_setter_t > m_acceptor_options_setter
Acceptor options setter.
std::size_t concurrent_accepts_count() const
std::unique_ptr< socket_options_setter_t > m_socket_options_setter
Socket options setter.
const details::address_variant_t & address() const
Definition settings.hpp:716
typename Traits::logger_t logger_t
Definition settings.hpp:950
Derived & port(std::uint16_t p) &
Server endpoint.
Definition settings.hpp:585
Derived && handle_request_timeout(std::chrono::steady_clock::duration d) &&
Definition settings.hpp:807
Derived & ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &
Setter for IP-blocker.
Derived && concurrent_accepts_count(std::size_t n) &&
Derived & buffer_size(std::size_t s) &
Size of buffer for io operations.
Definition settings.hpp:729
Derived & concurrent_accepts_count(std::size_t n) &
Max number of running concurrent accepts.
Derived && separate_accept_and_create_connect(bool do_separate) &&noexcept
Derived && cleanup_func(Func &&func) &&
Derived & max_parallel_connections(std::size_t value) &noexcept
Setter for connection count limit.
std::unique_ptr< socket_options_setter_t > socket_options_setter()
Derived && extra_data_factory(extra_data_factory_handle_t factory) &&
Setter for extra-data-factory.
Derived & request_handler(Params &&... params) &
Definition settings.hpp:855
Derived && socket_options_setter(socket_options_setter_t sos) &&
void ensure_valid_connection_state_listener()
Internal method for checking presence of state listener object.
std::uint16_t m_port
Server endpoint.
Derived && logger(Params &&... params) &&
Definition settings.hpp:963
std::unique_ptr< logger_t > m_logger
Logger.
Derived && max_parallel_connections(std::size_t value) &&noexcept
Setter for connection count limit.
Derived && timer_manager(Params &&... params) &&
Creates a factory object that will be used for creation of an actual timer_manager instance.
Definition settings.hpp:934
Derived & write_http_response_timelimit(std::chrono::steady_clock::duration d) &
A period of time wait for response to be written to socket.
Definition settings.hpp:778
std::shared_ptr< extra_data_factory_t > extra_data_factory_handle_t
Type of shared-pointer to extra-data-factory.
extra_data_factory_handle_t m_extra_data_factory
User-data-factory for server.
Derived & cleanup_func(Func &&func) &
std::unique_ptr< request_handler_t > request_handler()
Definition settings.hpp:871
Derived && acceptor_options_setter(acceptor_options_setter_t aos) &&
Definition settings.hpp:991
std::uint16_t port() const
Definition settings.hpp:599
Derived && connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &&
Setter for connection state listener.
Derived & protocol(asio_ns::ip::tcp p) &
Definition settings.hpp:605
Derived & request_handler(std::unique_ptr< request_handler_t > handler) &
Definition settings.hpp:847
basic_server_settings_t(std::uint16_t port=8080, asio_ns::ip::tcp protocol=asio_ns::ip::tcp::v4())
Definition settings.hpp:574
Derived && read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &&
Definition settings.hpp:763
Derived & incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &noexcept
Setter of optional limits for incoming HTTP messages.
Derived && ip_blocker(std::shared_ptr< typename Traits::ip_blocker_t > blocker) &&
Setter for IP-blocker.
Derived && max_pipelined_requests(std::size_t mpr) &&
Definition settings.hpp:829
extra_data_factory_handle_t giveaway_extra_data_factory() const noexcept
Extractor for extra-data-factory.
incoming_http_msg_limits_t m_incoming_http_msg_limits
Limits for incoming HTTP messages.
std::size_t buffer_size() const
Definition settings.hpp:742
asio_ns::ip::tcp protocol() const
Definition settings.hpp:619
Derived & handle_request_timeout(std::chrono::steady_clock::duration d) &
A period of time that is given for a handler to create response.
Definition settings.hpp:800
std::unique_ptr< timer_factory_t > m_timer_factory
Timers factory.
Derived & timer_manager(Params &&... params) &
Creates a factory object that will be used for creation of an actual timer_manager instance.
Definition settings.hpp:918
Derived && request_handler(Params &&... params) &&
Definition settings.hpp:865
Derived && address(std::string addr) &&
Definition settings.hpp:662
std::chrono::steady_clock::duration handle_request_timeout() const
Definition settings.hpp:813
Derived & logger(Params &&... params) &
Definition settings.hpp:954
std::unique_ptr< acceptor_options_setter_t > acceptor_options_setter()
Definition settings.hpp:997
Derived & address(asio_ns::ip::address addr) &
Definition settings.hpp:687
void ensure_valid_ip_blocker()
Internal method for checking presence of IP-blocker object.
Derived & acceptor_options_setter(acceptor_options_setter_t aos) &
Definition settings.hpp:980
Derived & extra_data_factory(extra_data_factory_handle_t factory) &
Setter for extra-data-factory.
Derived && write_http_response_timelimit(std::chrono::steady_clock::duration d) &&
Definition settings.hpp:785
std::chrono::steady_clock::duration read_next_http_message_timelimit() const
Definition settings.hpp:769
Derived & max_pipelined_requests(std::size_t mpr) &
Max pipelined requests able to receive on single connection.
Definition settings.hpp:822
Derived & set_unique_instance(std::unique_ptr< Target > &t, Params &&... params)
typename Traits::timer_manager_t timer_manager_t
Short alias for timer_manager type.
Definition settings.hpp:885
acceptor_post_bind_hook_t giveaway_acceptor_post_bind_hook()
A getter for post-bind callback.
typename Traits::extra_data_factory_t extra_data_factory_t
The actual type of extra-data-factory.
Derived & set_shared_instance(std::shared_ptr< Target > &t, Params &&... params)
const std::shared_ptr< typename Traits::connection_state_listener_t > & connection_state_listener() const noexcept
Get reference to connection state listener.
std::size_t max_pipelined_requests() const
Definition settings.hpp:835
Derived && acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &&
A setter for post-bind callback.
cleanup_functor_t m_cleanup_functor
Optional cleanup functor.
Derived && port(std::uint16_t p) &&
Definition settings.hpp:592
std::unique_ptr< timer_factory_t > timer_factory()
Definition settings.hpp:940
Derived && address(asio_ns::ip::address addr) &&
Definition settings.hpp:709
Derived & socket_options_setter(socket_options_setter_t sos) &
Derived & acceptor_post_bind_hook(acceptor_post_bind_hook_t hook) &
A setter for post-bind callback.
Derived && incoming_http_msg_limits(const incoming_http_msg_limits_t &limits) &&noexcept
Setter of optional limits for incoming HTTP messages.
std::chrono::steady_clock::duration write_http_response_timelimit() const
Definition settings.hpp:791
details::address_variant_t m_address
request_handler_type_from_traits_t< Traits > request_handler_t
Request handler.
Definition settings.hpp:844
Derived && buffer_size(std::size_t s) &&
Definition settings.hpp:736
Derived & separate_accept_and_create_connect(bool do_separate) &noexcept
Do separate an accept operation and connection instantiation.
Derived & read_next_http_message_timelimit(std::chrono::steady_clock::duration d) &
}
Definition settings.hpp:756
const incoming_http_msg_limits_t & incoming_http_msg_limits() const noexcept
Getter of optional limits for incoming HTTP messages.
Derived & address(std::string addr) &
Definition settings.hpp:642
cleanup_functor_t giveaway_cleanup_func()
Derived & connection_state_listener(std::shared_ptr< typename Traits::connection_state_listener_t > listener) &
Setter for connection state listener.
Derived && protocol(asio_ns::ip::tcp p) &&
Definition settings.hpp:612
bool separate_accept_and_create_connect() const noexcept
std::unique_ptr< logger_t > logger()
Definition settings.hpp:969
An implementation of connection count limiter for the case when connection count is not limited.
Exception class for all exceptions thrown by RESTinio.
Definition exception.hpp:26
A type of holder of limits related to an incoming HTTP message.
A fluent style interface for setting http server params.
An adapter for setting acceptor options before running server.
Definition settings.hpp:248
void set_option(const Option &option, asio_ns::error_code &ec)
Definition settings.hpp:267
asio_ns::basic_socket< asio_ns::ip::tcp > & m_socket
A reference on the most base class with interface of setting options.
Definition settings.hpp:289
void get_option(Option &option)
Definition settings.hpp:274
void get_option(Option &option, asio_ns::error_code &ec)
Definition settings.hpp:281
socket_options_t(asio_ns::basic_socket< asio_ns::ip::tcp > &socket)
Definition settings.hpp:250
void set_option(const Option &option)
API for setting/getting options.
Definition settings.hpp:260
Extra settings needed for working with socket.
Definition settings.hpp:154
~socket_type_dependent_settings_t() noexcept=default
#define RESTINIO_FMT_FORMAT_STRING(s)
Stuff related to limits of an incoming HTTP message.
std::variant< no_address_specified_t, std::string, asio_ns::ip::address > address_variant_t
A type of variant for holding IP address for a server in various representations.
Definition settings.hpp:459
inspection_result_t
Enumeration of result of inspecting new incoming connection.
typename details::actual_request_handler_type_detector< typename Traits::request_handler_t, typename Traits::extra_data_factory_t >::request_handler_t request_handler_type_from_traits_t
A metafunction for extraction a request-handler type from server's traits.
Definition traits.hpp:375
auto ensure_created(std::unique_ptr< Object > mb_created_one, string_view_t fail_description)
Ensure that object was created.
Definition settings.hpp:113
auto create_default_unique_object_instance< acceptor_options_setter_t >()
Definition settings.hpp:229
run_on_this_thread_settings_t< Traits > on_this_thread()
A special marker for the case when http_server must be run on the context of the current thread.
std::function< void(socket_options_t &) > socket_options_setter_t
Definition settings.hpp:292
auto create_default_shared_object_instance()
Default instantiation for a specific type.
Definition settings.hpp:91
std::function< void(acceptor_options_t &) > acceptor_options_setter_t
Definition settings.hpp:225
std::string_view string_view_t
auto exec_configurator(Configurator &&configurator)
std::function< void(void) > cleanup_functor_t
Type of holder for user's cleanup function.
Definition settings.hpp:307
auto create_default_shared_object_instance< default_request_handler_t >()
Default instantiation for default_request_handler_t.
Definition settings.hpp:100
auto create_default_unique_object_instance()
Default instantiation for a specific type.
Definition settings.hpp:69
auto create_default_unique_object_instance< default_request_handler_t >()
Default instantiation for default_request_handler_t.
Definition settings.hpp:78
std::function< void(asio_ns::ip::tcp::acceptor &) > acceptor_post_bind_hook_t
A type of callback to be called after a successful invocation of bind() function for the acceptor.
Definition settings.hpp:433
auto create_default_unique_object_instance< socket_options_setter_t >()
Definition settings.hpp:296
typename std::conditional< Traits::use_connection_count_limiter, connection_count_limits::connection_count_limiter_t< typename Traits::strand_t >, connection_count_limits::noop_connection_count_limiter_t >::type limiter_t
A special class for holding actual connection state listener.
Definition settings.hpp:323
std::shared_ptr< Listener > m_connection_state_listener
Definition settings.hpp:324
void check_valid_connection_state_listener_pointer() const
Checks that pointer to state listener is not null.
Definition settings.hpp:333
A special type for holding the value of maximum allowed count of parallel connections.
Definition settings.hpp:481
void set_max_parallel_connections(std::size_t v) noexcept
Definition settings.hpp:500
std::size_t max_parallel_connections() const noexcept
Definition settings.hpp:494
A special indicator for the case when IP address for a server is not set explicitly.
Definition settings.hpp:448
A special class for holding actual IP-blocker object.
Definition settings.hpp:374
void check_valid_ip_blocker_pointer() const
Checks that pointer to IP-blocker is not null.
Definition settings.hpp:397
std::shared_ptr< Ip_Blocker > m_ip_blocker
Definition settings.hpp:388