RESTinio
Loading...
Searching...
No Matches
settings.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
5/*!
6 HTTP-Server configuration.
7*/
8
9#pragma once
10
11#include <restinio/asio_include.hpp>
12
13#include <restinio/exception.hpp>
14#include <restinio/request_handler.hpp>
15#include <restinio/traits.hpp>
16
17#include <restinio/incoming_http_msg_limits.hpp>
18
19#include <chrono>
20#include <variant>
21#include <tuple>
22#include <utility>
23
24namespace restinio
25{
26
27namespace details
28{
29
30//! Default instantiation for a specific type.
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
45//! Default instantiation for a specific type.
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
66//! Default instantiation for a specific type.
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
75//! Default instantiation for default_request_handler_t.
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
88//! Default instantiation for a specific type.
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
97//! Default instantiation for default_request_handler_t.
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
110//! Ensure that object was created.
111template < typename Object >
112auto
114 std::unique_ptr< Object > mb_created_one,
115 string_view_t fail_description )
116{
117 if( !mb_created_one )
118 mb_created_one = create_default_unique_object_instance< Object >();
119
120 if( !mb_created_one )
121 throw exception_t{ fail_description };
122
123 return mb_created_one;
124}
125
126//
127// unsure_created()
128//
129
130//! Ensure that object was created.
131template < typename Object >
132auto
134 std::shared_ptr< Object > mb_created_one,
135 string_view_t fail_description )
136{
137 if( !mb_created_one )
138 mb_created_one = create_default_shared_object_instance< Object >();
139
140 if( !mb_created_one )
141 throw exception_t{ fail_description };
142
143 return mb_created_one;
144}
145
146
147//
148// socket_type_dependent_settings_t
149//
150
151//! Extra settings needed for working with socket.
152template < typename Settings, typename Socket >
154{
155protected :
156 ~socket_type_dependent_settings_t() noexcept = default;
157
158public :
160
163
165 operator=(const socket_type_dependent_settings_t &) noexcept = default;
166
169
170 // No extra settings by default.
171};
172
173//
174// acceptor_options_t
175//
176
177//! An adapter for setting acceptor options before running server.
178/*!
179 Class hides an acceptor object and opens only set/get options API.
180 It is used as an argument for a user defined function-object
181 that can set custom options for acceptor.
182*/
184{
185 public:
186 acceptor_options_t( asio_ns::ip::tcp::acceptor & acceptor )
187 : m_acceptor{ acceptor }
188 {}
189
190 //! API for setting/getting options.
191 //! \{
192 template< typename Option >
193 void
194 set_option( const Option & option )
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
208 get_option( Option & option )
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 }
219 //! \}
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 >(
232 []( acceptor_options_t & options ){
233 options.set_option( asio_ns::ip::tcp::acceptor::reuse_address( true ) );
234 } );
235}
236
237//
238// socket_options_t
239//
240
241//! An adapter for setting acceptor options before running server.
242/*!
243 Class hides a socket object and opens only set/get options API.
244 It is used as an argument for a user defined function-object
245 that can set custom options for socket.
246*/
248{
249 public:
251 //! A reference on the most base class with interface of setting options.
252 asio_ns::basic_socket< asio_ns::ip::tcp > & socket )
253 : m_socket{ socket }
254 {}
255
256 //! API for setting/getting options.
257 //! \{
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 }
285 //! \}
286
287 private:
288 //! A reference on the most base class with interface of setting options.
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//
304/*!
305 * \brief Type of holder for user's cleanup function.
306 */
307using cleanup_functor_t = std::function< void(void) >;
308
309//
310// connection_state_listener_holder_t
311//
312/*!
313 * @brief A special class for holding actual connection state listener.
314 *
315 * This class holds shared pointer to actual connection state listener
316 * and provides an actual implementation of
317 * check_valid_connection_state_listener_pointer() method.
318 *
319 * @since v.0.5.1
320 */
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
328 //! Checks that pointer to state listener is not null.
329 /*!
330 * Throws an exception if m_connection_state_listener is nullptr.
331 */
332 void
334 {
336 throw exception_t{ "connection state listener is not specified" };
337 }
338};
339
340/*!
341 * @brief A special class for case when no-op state listener is used.
342 *
343 * Doesn't hold anything and contains empty
344 * check_valid_connection_state_listener_pointer() method.
345 *
346 * @since v.0.5.1
347 */
348template<>
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//
363/*!
364 * @brief A special class for holding actual IP-blocker object.
365 *
366 * This class holds shared pointer to actual IP-blocker
367 * and provides an actual implementation of
368 * check_valid_ip_blocker_pointer() method.
369 *
370 * @since v.0.5.1
371 */
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(
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
392 //! Checks that pointer to IP-blocker is not null.
393 /*!
394 * Throws an exception if m_ip_blocker is nullptr.
395 */
396 void
398 {
399 if( !m_ip_blocker )
400 throw exception_t{ "IP-blocker is not specified" };
401 }
402};
403
404/*!
405 * @brief A special class for case when no-op IP-blocker is used.
406 *
407 * Doesn't hold anything and contains empty
408 * check_valid_ip_blocker_pointer() method.
409 *
410 * @since v.0.5.1
411 */
412template<>
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//
427/*!
428 * @brief A type of callback to be called after a successful invocation
429 * of bind() function for the acceptor.
430 *
431 * @since v.0.6.11
432 */
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//
442/*!
443 * @brief A special indicator for the case when IP address for a server
444 * is not set explicitly.
445 *
446 * @since v.0.6.11
447 */
449
450//
451// address_variant_t
452//
453/*!
454 * @brief A type of variant for holding IP address for a server in
455 * various representations.
456 *
457 * @since v.0.6.11
458 */
459using address_variant_t = std::variant<
461 std::string,
462 asio_ns::ip::address >;
463
464//
465// max_parallel_connections_holder_t
466//
467/*!
468 * @brief A special type for holding the value of maximum allowed
469 * count of parallel connections.
470 *
471 * This type is intended to be used as a mixin for
472 * server_settings_t type.
473 *
474 * Holds the value and provides the actual implementations for
475 * getter and setter of that value.
476 *
477 * @since v.0.6.12
478 */
479template< typename Count_Limiter >
481{
482 static constexpr bool has_actual_max_parallel_connections = true;
483
484 /*!
485 * @brief Actual value of the limit.
486 *
487 * By the default the count of parallel connection is not limited.
488 */
490 std::numeric_limits<std::size_t>::max()
491 };
492
493 std::size_t
495 {
497 }
498
499 void
500 set_max_parallel_connections( std::size_t v ) noexcept
501 {
503 }
504};
505
506/*!
507 * @brief A specialization of max_parallel_connections_holder for the case
508 * when connection count isn't limited.
509 *
510 * Doesn't hold anything. Hasn't a setter.
511 *
512 * The getter returns a value that means that there is no connection
513 * count limit at all.
514 *
515 * @since v.0.6.12
516 */
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
536//! Basic container for http_server settings.
537/*!
538 * It exists to provide ablity to create various derived classes
539 * like server_settings_t, run_on_this_thread_settings_t,
540 * run_on_this_thread_settings_t and so on.
541 *
542 * \tparam Derived A drived type. Reference to this derived type
543 * will be returned by setters.
544 *
545 * \tparam Traits A type with traits for http_server.
546 */
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
561 typename connection_count_limit_types<Traits>::limiter_t >;
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
582 //! Server endpoint.
583 //! \{
584 Derived &
585 port( std::uint16_t p ) &
586 {
587 m_port = p;
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;
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
624 /*!
625 * Sets the IP address for a server in textual form.
626 *
627 * Usage example:
628 * @code
629 * using my_server_t = restinio::http_server_t< my_server_traits_t >;
630 * my_server_t server{
631 * restinio::own_io_context(),
632 * [](auto & settings) {
633 * settings.port(8080);
634 * settings.address("192.168.1.1");
635 * settings.request_handler(...);
636 * ...
637 * }
638 * };
639 * @endcode
640 */
641 Derived &
642 address( std::string addr ) &
643 {
644 m_address = std::move(addr);
646 }
647
648 /*!
649 * Sets the IP address for a server in textual form.
650 *
651 * Usage example:
652 * @code
653 * restinio::run(
654 * restinio::on_this_thread()
655 * .port(...)
656 * .address("192.168.1.1")
657 * .request_handler(...)
658 * );
659 * @endcode
660 */
661 Derived &&
662 address( std::string addr ) &&
663 {
664 return std::move( this->address( std::move( addr ) ) );
665 }
666
667 /*!
668 * Sets the IP address for a server in binary form.
669 *
670 * Usage example:
671 * @code
672 * auto actual_ip = asio::ip::address::from_string(app.config().ip_addr());
673 * ...
674 * using my_server_t = restinio::http_server_t< my_server_traits_t >;
675 * my_server_t server{
676 * restinio::own_io_context(),
677 * [actual_ip](auto & settings) {
678 * settings.port(8080);
679 * settings.address(actual_ip);
680 * settings.request_handler(...);
681 * ...
682 * }
683 * };
684 * @endcode
685 */
686 Derived &
687 address( asio_ns::ip::address addr ) &
688 {
689 m_address = addr;
691 }
692
693 /*!
694 * Sets the IP address for a server in binary form.
695 *
696 * Usage example:
697 * @code
698 * auto actual_ip = asio::ip::address::from_string(app.config().ip_addr());
699 * ...
700 * restinio::run(
701 * restinio::on_this_thread()
702 * .port(...)
703 * .address(actual_ip)
704 * .request_handler(...)
705 * );
706 * @endcode
707 */
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 }
720 //! \}
721
722 //! Size of buffer for io operations.
723 /*!
724 It limits a size of chunk that can be read from socket in a single
725 read operattion (async read).
726 */
727 //! {
728 Derived &
729 buffer_size( std::size_t s ) &
730 {
731 m_buffer_size = s;
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 }
746 //! }
747
748 //! A period for holding connection before completely receiving
749 //! new http-request. Starts counting since connection is establised
750 //! or a previous request was responsed.
751 /*!
752 Generaly it defines timeout for keep-alive connections.
753 */
754 //! \{
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 );
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 }
773 //! \}
774
775 //! A period of time wait for response to be written to socket.
776 //! \{
777 Derived &
778 write_http_response_timelimit( std::chrono::steady_clock::duration d ) &
779 {
780 m_write_http_response_timelimit = std::move( d );
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 }
795 //! \}
796
797 //! A period of time that is given for a handler to create response.
798 //! \{
799 Derived &
800 handle_request_timeout( std::chrono::steady_clock::duration d ) &
801 {
802 m_handle_request_timeout = std::move( d );
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 }
817 //! \}
818
819 //! Max pipelined requests able to receive on single connection.
820 //! \{
821 Derived &
822 max_pipelined_requests( std::size_t mpr ) &
823 {
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 {
838 }
839 //! \}
840
841
842 //! Request handler.
843 //! \{
845
846 Derived &
847 request_handler( std::unique_ptr< request_handler_t > handler ) &
848 {
849 m_request_handler = std::move( handler );
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
872 {
873 return ensure_created(
874 std::move( m_request_handler ),
875 "request handler must be set" );
876 }
877 //! \}
878
879
880 //! \name Timers manager.
881 //! \{
882 /*!
883 * @brief Short alias for timer_manager type.
884 */
885 using timer_manager_t = typename Traits::timer_manager_t;
886 /*!
887 * @brief Short alias for type of a factory that creates
888 * instances of timer_manager.
889 */
891
892 /*!
893 * @brief Creates a factory object that will be used for creation
894 * of an actual timer_manager instance.
895 *
896 * An instance of @a Traits::timer_manager_t::factory_t is created
897 * dynamically. All @a params are passed to std::make_unique call
898 * and will be forwarded to the constructor of @a timer_factory_t.
899 *
900 * Usage example:
901 * @code
902 * struct my_traits : public restinio::traits_t<
903 * restinio::asio_timer_manager_t, my_logger >
904 * {
905 * using request_handler_t = ...; // Some request handler type.
906 * };
907 * ...
908 * restinio::run(
909 * restinio::on_this_thread<my_traits>()
910 * .port(8080)
911 * .address("localhost")
912 * .timer_manager(std::chrono::milliseconds{250})
913 * .request_handler(...));
914 * @endcode
915 */
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
925 /*!
926 * @brief Creates a factory object that will be used for creation
927 * of an actual timer_manager instance.
928 *
929 * For more information and usage example see the documentation
930 * for another overload.
931 */
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
941 {
942 return ensure_created(
943 std::move( m_timer_factory ),
944 "timer manager is not set" );
945 }
946 //! \}
947
948 //! \name Logger.
949 //! \{
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
970 {
971 return ensure_created(
972 std::move( m_logger ),
973 "logger must be set" );
974 }
975 //! \}
976
977 //! \name Acceptor options setter.
978 //! \{
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
998 {
999 return ensure_created(
1000 std::move( m_acceptor_options_setter ),
1001 "acceptor options setter must be set" );
1002 }
1003 //! \}
1004
1005 //! \name Socket options setter.
1006 //! \{
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
1026 {
1027 return ensure_created(
1028 std::move( m_socket_options_setter ),
1029 "socket options setter must be set" );
1030 }
1031 //! \}
1032
1033 //! Max number of running concurrent accepts.
1034 /*!
1035 When running server on N threads
1036 then up to N accepts can be handled concurrently.
1037 */
1038 //! \{
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
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 {
1063 }
1064 //! \}
1065
1066 //! Do separate an accept operation and connection instantiation.
1067 /*!
1068 For the cases when a lot of connection can be fired by clients
1069 in a short time interval, it is vital to accept connections
1070 and initiate new accept operations as quick as possible.
1071 So creating connection instance that involves allocations
1072 and initialization can be done in a context that
1073 is independent to acceptors one.
1074 */
1075 //! \{
1076 Derived &
1077 separate_accept_and_create_connect( bool do_separate ) & noexcept
1078 {
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
1094 //! \}
1095
1096 //! \name Cleanup function.
1097 //! \{
1098 template< typename Func >
1099 Derived &
1100 cleanup_func( Func && func ) &
1101 {
1102 m_cleanup_functor = std::move(func);
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
1113 /*!
1114 * @note
1115 * This method is intended to be used by RESTinio and it can be
1116 * changed or removed in future versions of RESTinio without any
1117 * notice.
1118 */
1119 [[nodiscard]]
1122 {
1123 return std::move(m_cleanup_functor);
1124 }
1125 //! \}
1126
1127 /*!
1128 * @brief Setter for connection state listener.
1129 *
1130 * @note connection_state_listener() method should be called if
1131 * user specify its type for connection_state_listener_t traits.
1132 * For example:
1133 * @code
1134 * class my_state_listener_t {
1135 * ...
1136 * public:
1137 * ...
1138 * void state_changed(const restinio::connection_state::notice_t & notice) noexcept {
1139 * ...
1140 * }
1141 * };
1142 *
1143 * struct my_traits_t : public restinio::default_traits_t {
1144 * using connection_state_listener_t = my_state_listener_t;
1145 * };
1146 *
1147 * restinio::server_setting_t<my_traits_t> settings;
1148 * setting.connection_state_listener( std::make_shared<my_state_listener_t>(...) );
1149 * ...
1150 * @endcode
1151 *
1152 * @attention This method can't be called if the default no-op
1153 * state listener is used in server traits.
1154 *
1155 * @since v.0.5.1
1156 */
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);
1168 }
1169
1170 /*!
1171 * @brief Setter for connection state listener.
1172 *
1173 * @note connection_state_listener() method should be called if
1174 * user specify its type for connection_state_listener_t traits.
1175 * For example:
1176 * @code
1177 * class my_state_listener_t {
1178 * ...
1179 * public:
1180 * ...
1181 * void state_changed(const restinio::connection_state::notice_t & notice) noexcept {
1182 * ...
1183 * }
1184 * };
1185 *
1186 * struct my_traits_t : public restinio::default_traits_t {
1187 * using connection_state_listener_t = my_state_listener_t;
1188 * };
1189 *
1190 * restinio::run( restinio::on_this_thread<my_traits_t>()
1191 * .connection_state_listener( std::make_shared<my_state_listener_t>(...) )
1192 * .port(...)
1193 * ...);
1194 * @endcode
1195 *
1196 * @attention This method can't be called if the default no-op
1197 * state listener is used in server traits.
1198 *
1199 * @since v.0.5.1
1200 */
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
1209 /*!
1210 * @brief Get reference to connection state listener.
1211 *
1212 * @attention This method can't be called if the default no-op
1213 * state listener is used in server traits.
1214 *
1215 * @since v.0.5.1
1216 */
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
1228 /*!
1229 * @brief Internal method for checking presence of state listener
1230 * object.
1231 *
1232 * If a user specifies custom state listener type but doesn't
1233 * set a pointer to listener object that method throws an exception.
1234 *
1235 * @since v.0.5.1
1236 */
1237 void
1239 {
1240 this->check_valid_connection_state_listener_pointer();
1241 }
1242
1243 /*!
1244 * @brief Setter for IP-blocker.
1245 *
1246 * @note ip_blocker() method should be called if
1247 * user specify its type for ip_blocker_t traits.
1248 * For example:
1249 * @code
1250 * class my_ip_blocker_t {
1251 * ...
1252 * public:
1253 * ...
1254 * restinio::ip_blocker::inspection_result_t
1255 * inspect(const restinio::ip_blocker::incoming_info_t & info) noexcept {
1256 * ...
1257 * }
1258 * };
1259 *
1260 * struct my_traits_t : public restinio::default_traits_t {
1261 * using ip_blocker_t = my_ip_blocker_t;
1262 * };
1263 *
1264 * restinio::server_setting_t<my_traits_t> settings;
1265 * setting.ip_blocker( std::make_shared<my_ip_blocker_t>(...) );
1266 * ...
1267 * @endcode
1268 *
1269 * @attention This method can't be called if the default no-op
1270 * IP-blocker is used in server traits.
1271 *
1272 * @since v.0.5.1
1273 */
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);
1285 }
1286
1287 /*!
1288 * @brief Setter for IP-blocker.
1289 *
1290 * @note ip_blocker() method should be called if
1291 * user specify its type for ip_blocker_t traits.
1292 * For example:
1293 * @code
1294 * class my_ip_blocker_t {
1295 * ...
1296 * public:
1297 * ...
1298 * restinio::ip_blocker::inspection_result_t
1299 * inspect(const restinio::ip_blocker::incoming_info_t & info) noexcept {
1300 * ...
1301 * }
1302 * };
1303 *
1304 * struct my_traits_t : public restinio::default_traits_t {
1305 * using ip_blocker_t = my_ip_blocker_t;
1306 * };
1307 *
1308 * restinio::run( restinio::on_this_thread<my_traits_t>()
1309 * .ip_blocker( std::make_shared<my_ip_blocker_t>(...) )
1310 * .port(...)
1311 * ...);
1312 * @endcode
1313 *
1314 * @attention This method can't be called if the default no-op
1315 * state listener is used in server traits.
1316 *
1317 * @since v.0.5.1
1318 */
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
1326 /*!
1327 * @brief Get reference to IP-blocker.
1328 *
1329 * @attention This method can't be called if the default no-op
1330 * IP-blocker is used in server traits.
1331 *
1332 * @since v.0.5.1
1333 */
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
1345 /*!
1346 * @brief Internal method for checking presence of IP-blocker object.
1347 *
1348 * If a user specifies custom IP-blocker type but doesn't
1349 * set a pointer to blocker object that method throws an exception.
1350 *
1351 * @since v.0.5.1
1352 */
1353 void
1355 {
1356 this->check_valid_ip_blocker_pointer();
1357 }
1358
1359 // Acceptor post-bind hook.
1360 /*!
1361 * @brief A setter for post-bind callback.
1362 *
1363 * Usage example:
1364 * @code
1365 * using my_server_t = restinio::http_server_t< my_server_traits_t >;
1366 * my_server_t server{
1367 * restinio::own_io_context(),
1368 * [](auto & settings) {
1369 * settings.port(...);
1370 * settings.address(...);
1371 * settings.acceptor_post_bind_hook(
1372 * [](asio::ip::tcp::acceptor & acceptor) {
1373 * ...
1374 * })
1375 * settings.request_handler(...);
1376 * ...
1377 * }
1378 * };
1379 * @endcode
1380 *
1381 * @since v.0.6.11
1382 */
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);
1391 }
1392
1393 /*!
1394 * @brief A setter for post-bind callback.
1395 *
1396 * Usage example:
1397 * @code
1398 * restinio::run(
1399 * restinio::on_this_thread()
1400 * .port(...)
1401 * .address(...)
1402 * .acceptor_post_bind_hook(
1403 * [](asio::ip::tcp::acceptor & acceptor) {
1404 * ...
1405 * })
1406 * .request_handler(...)
1407 * );
1408 * @endcode
1409 *
1410 * @since v.0.6.11
1411 */
1412 Derived &&
1414 {
1415 return std::move(this->acceptor_post_bind_hook( std::move(hook) ));
1416 }
1417
1418 /*!
1419 * @brief A getter for post-bind callback.
1420 *
1421 * @note
1422 * This method is intended to be used by RESTinio and it can be
1423 * changed or removed in future versions of RESTinio without any
1424 * notice.
1425 *
1426 * @since v.0.6.11
1427 */
1428 [[nodiscard]]
1431 {
1432 return std::move(m_acceptor_post_bind_hook);
1433 }
1434
1435 /*!
1436 * @brief Getter of optional limits for incoming HTTP messages.
1437 *
1438 * In v.0.6.12 if the limits for incoming HTTP messages are not
1439 * set explicitely then a defaultly constructed instance of
1440 * incoming_http_msg_limits_t is used. This means the absence of
1441 * any limits.
1442 *
1443 * But if the limits were set by using appropriate setters then
1444 * a reference to an instance with user-defined limits is returned.
1445 *
1446 * @since v.0.6.12
1447 */
1448 [[nodiscard]]
1451 {
1453 }
1454
1455 /*!
1456 * @brief Setter of optional limits for incoming HTTP messages.
1457 *
1458 * Usage example:
1459 * @code
1460 * struct my_traits : public restinio::default_traits_t { ... };
1461 * restinio::server_settings_t<my_traits> settings;
1462 * settings.incoming_http_msg_limits(
1463 * restinio::incoming_http_msg_limits_t{}
1464 * .max_url_size(8000u)
1465 * .max_field_name_size(2048u)
1466 * .max_field_value_size(4096u)
1467 * );
1468 * ...
1469 * auto server = restinio::run_async(
1470 * restinio::own_io_context(),
1471 * std::move(settings),
1472 * std::thread::hardware_concurrency());
1473 * @endcode
1474 *
1475 * @since v.0.6.12
1476 */
1477 Derived &
1479 const incoming_http_msg_limits_t & limits ) & noexcept
1480 {
1483 }
1484
1485 /*!
1486 * @brief Setter of optional limits for incoming HTTP messages.
1487 *
1488 * Usage example:
1489 * @code
1490 * struct my_traits : public restinio::default_traits_t { ... };
1491 * ...
1492 * auto server = restinio::run_async(
1493 * restinio::own_io_context(),
1494 * restinio::server_settings_t<my_traits>{}
1495 * ...
1496 * .incoming_http_msg_limits(
1497 * restinio::incoming_http_msg_limits_t{}
1498 * .max_url_size(8000u)
1499 * .max_field_name_size(2048u)
1500 * .max_field_value_size(4096u)
1501 * ),
1502 * std::thread::hardware_concurrency());
1503 * @endcode
1504 *
1505 * @since v.0.6.12
1506 */
1507 Derived &&
1509 const incoming_http_msg_limits_t & limits ) && noexcept
1510 {
1511 return std::move(this->incoming_http_msg_limits(limits));
1512 }
1513
1514 /*!
1515 * @brief Setter for connection count limit.
1516 *
1517 * @note
1518 * This setter can be called only if the usage of connection
1519 * count limit is turned on explicitly.
1520 *
1521 * Usage example:
1522 * @code
1523 * struct my_traits : public restinio::default_traits_t {
1524 * static constexpr bool use_connection_count_limiter = true;
1525 * };
1526 * ...
1527 * restinio::server_settings_t<my_traits> settings;
1528 * settings.max_parallel_connections( 1000u );
1529 * ...
1530 * auto server = restinio::run_async(
1531 * restinio::own_io_context(),
1532 * std::move(settings),
1533 * std::thread::hardware_concurrency());
1534 * @endcode
1535 *
1536 * @since v.0.6.12
1537 */
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 );
1548 }
1549
1550 /*!
1551 * @brief Setter for connection count limit.
1552 *
1553 * @note
1554 * This setter can be called only if the usage of connection
1555 * count limit is turned on explicitly.
1556 *
1557 * Usage example:
1558 * @code
1559 * struct my_traits : public restinio::default_traits_t {
1560 * static constexpr bool use_connection_count_limiter = true;
1561 * };
1562 * ...
1563 * auto server = restinio::run_async(
1564 * restinio::own_io_context(),
1565 * restinio::server_settings_t<my_traits>{}
1566 * ...
1567 * .max_parallel_connections(1000u),
1568 * std::thread::hardware_concurrency());
1569 * @endcode
1570 *
1571 * @since v.0.6.12
1572 */
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
1581 /*!
1582 * @name User-data factory.
1583 * @{
1584 */
1585 /*!
1586 * @brief The actual type of extra-data-factory.
1587 * @since v.0.6.13
1588 */
1590 /*!
1591 * @brief Type of shared-pointer to extra-data-factory.
1592 * @since v.0.6.13
1593 */
1595
1596 /*!
1597 * @brief Setter for extra-data-factory.
1598 *
1599 * Usage example:
1600 * @code
1601 * class my_extra_data_factory {
1602 * ... // Some factory's data.
1603 * public:
1604 * struct data_t {...};
1605 *
1606 * my_extra_data_factory(...) {...}
1607 *
1608 * void make_within(restinio::extra_data_buffer_t<data_t> buf) {
1609 * new(buf.get()) data_t{...};
1610 * }
1611 * };
1612 *
1613 * struct my_traits : public restinio::default_traits_t {
1614 * using extra_data_factory_t = my_extra_data_factory;
1615 * };
1616 *
1617 * restinio::server_settings_t<my_traits> settings;
1618 * ...
1619 * settings.extra_data_factory(std::make_shared<my_extra_data_factory>(...));
1620 * ...
1621 * auto server = restinio::run_async(
1622 * restinio::own_io_context(),
1623 * std::move(settings),
1624 * std::thread::hardware_concurrency());
1625 * @endcode
1626 *
1627 * @since v.0.6.13
1628 */
1629 Derived &
1631 extra_data_factory_handle_t factory ) &
1632 {
1633 this->m_extra_data_factory = std::move(factory);
1635 }
1636
1637 /*!
1638 * @brief Setter for extra-data-factory.
1639 *
1640 * Usage example:
1641 * @code
1642 * class my_extra_data_factory {
1643 * ... // Some factory's data.
1644 * public:
1645 * struct data_t {...};
1646 *
1647 * my_extra_data_factory(...) {...}
1648 *
1649 * void make_within(restinio::extra_data_buffer_t<data_t> buf) {
1650 * new(buf.get()) data_t{...};
1651 * }
1652 * };
1653 *
1654 * struct my_traits : public restinio::default_traits_t {
1655 * using extra_data_factory_t = my_extra_data_factory;
1656 * };
1657 *
1658 * auto server = restinio::run_async(
1659 * restinio::own_io_context(),
1660 * restinio::server_settings_t<my_traits>{}
1661 * .extra_data_factory(std::make_shared<my_extra_data_factory>(...))
1662 * ...
1663 * ,
1664 * std::thread::hardware_concurrency());
1665 * @endcode
1666 *
1667 * @since v.0.6.13
1668 */
1669 Derived &&
1671 extra_data_factory_handle_t factory ) &&
1672 {
1673 return std::move(this->extra_data_factory( std::move(factory) ));
1674 }
1675
1676 /*!
1677 * @brief Extractor for extra-data-factory.
1678 * @since v.0.6.13
1679 */
1680 [[nodiscard]]
1683 {
1684 return ensure_created(
1685 std::move(this->m_extra_data_factory),
1686 "extra_data_factory is not set" );
1687 }
1688 /*!
1689 * @}
1690 */
1691
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
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
1719 }
1720
1721 //! Server endpoint.
1722 //! \{
1724 asio_ns::ip::tcp m_protocol;
1725 /*!
1726 * @note
1727 * This member has type address_variant_t since v.0.6.11
1728 */
1730 //! \}
1731
1732 //! Size of buffer for io operations.
1733 std::size_t m_buffer_size{ 4 * 1024 };
1734
1735 //! Operations timeouts.
1736 //! \{
1737 std::chrono::steady_clock::duration
1739
1740 std::chrono::steady_clock::duration
1742
1743 std::chrono::steady_clock::duration
1745 //! \}
1746
1747 //! Max pipelined requests to receive on single connection.
1749
1750 //! Request handler.
1752
1753 //! Timers factory.
1755
1756 //! Logger.
1758
1759 //! Acceptor options setter.
1761
1762 //! A hook to be called just after a successful call to bind for acceptor.
1763 /*!
1764 * An empty lambda is used by default.
1765 *
1766 * @since v.0.6.11
1767 */
1771
1772 //! Socket options setter.
1774
1776
1777 //! Do separate an accept operation and connection instantiation.
1779
1780 //! Optional cleanup functor.
1782
1783 /*!
1784 * @brief Limits for incoming HTTP messages.
1785 *
1786 * @since v.0.6.12
1787 */
1789
1790 /*!
1791 * @brief User-data-factory for server.
1792 *
1793 * @since v.0.6.13
1794 */
1796};
1797
1798//
1799// server_settings_t
1800//
1801
1802//! A fluent style interface for setting http server params.
1803template<typename Traits = default_traits_t>
1804class server_settings_t final
1805 : public basic_server_settings_t< server_settings_t<Traits>, Traits >
1806{
1808 server_settings_t<Traits>, Traits>;
1809public:
1810 using base_type_t::base_type_t;
1811};
1812
1813template < typename Traits, typename Configurator >
1814auto
1815exec_configurator( Configurator && configurator )
1816{
1817 server_settings_t< Traits > result;
1818
1819 configurator( result );
1820
1821 return result;
1822}
1823
1824} /* namespace restinio */
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 m_buffer_size
Size of buffer for io operations.
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) &&
acceptor_post_bind_hook_t m_acceptor_post_bind_hook
A hook to be called just after a successful call to bind for acceptor.
std::chrono::steady_clock::duration m_handle_request_timeout
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()
std::chrono::steady_clock::duration m_write_http_response_timelimit
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
socket_type_dependent_settings_t< Derived, typename Traits::stream_socket_t > base_type_t
Definition settings.hpp:556
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.
std::size_t m_max_pipelined_requests
Max pipelined requests to receive on single connection.
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
details::max_parallel_connections_holder_t< typename connection_count_limit_types< Traits >::limiter_t > max_parallel_connections_holder_base_t
Definition settings.hpp:559
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
bool m_separate_accept_and_create_connect
Do separate an accept operation and connection instantiation.
acceptor_post_bind_hook_t giveaway_acceptor_post_bind_hook()
A getter for post-bind callback.
std::chrono::steady_clock::duration m_read_next_http_message_timelimit
Operations timeouts.
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
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
exception_t(const char *err)
Definition exception.hpp:29
A type of holder of limits related to an incoming HTTP message.
An information about new incoming connection to be passed to IP-blocker object.
basic_server_settings_t< server_settings_t< Traits >, Traits > base_type_t
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 & operator=(socket_type_dependent_settings_t &&) noexcept=delete
socket_type_dependent_settings_t() noexcept=default
socket_type_dependent_settings_t(socket_type_dependent_settings_t &&) noexcept=default
socket_type_dependent_settings_t(const socket_type_dependent_settings_t &) noexcept=default
~socket_type_dependent_settings_t() noexcept=default
socket_type_dependent_settings_t & operator=(const socket_type_dependent_settings_t &) noexcept=default
#define RESTINIO_FMT_FORMAT_STRING(s)
auto create_default_unique_object_instance(std::false_type)
Default instantiation for a specific type.
Definition settings.hpp:33
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
auto create_default_shared_object_instance(std::false_type)
Default instantiation for a specific type.
Definition settings.hpp:48
auto ensure_created(std::unique_ptr< Object > mb_created_one, string_view_t fail_description)
Ensure that object was created.
Definition settings.hpp:113
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
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 ensure_created(std::shared_ptr< Object > mb_created_one, string_view_t fail_description)
Ensure that object was created.
Definition settings.hpp:133
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
A kind of metafunction that deduces actual types related to connection count limiter in the dependecy...
A special class for case when no-op state listener is used.
Definition settings.hpp:350
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
static constexpr bool has_actual_connection_state_listener
Definition settings.hpp:326
void check_valid_connection_state_listener_pointer() const
Checks that pointer to state listener is not null.
Definition settings.hpp:333
A specialization of max_parallel_connections_holder for the case when connection count isn't limited.
Definition settings.hpp:520
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 m_max_parallel_connections
Actual value of the limit.
Definition settings.hpp:489
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
The default no-op IP-blocker.
A special class for case when no-op IP-blocker is used.
Definition settings.hpp:414
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
static constexpr bool has_actual_ip_blocker
Definition settings.hpp:390