RESTinio
connection_settings.hpp
Go to the documentation of this file.
1 /*
2  restinio
3 */
4 
5 /*!
6  Connection settings.
7 */
8 
9 #pragma once
10 
11 #include <memory>
12 #include <chrono>
13 
14 #include <http_parser.h>
15 
16 #include <restinio/connection_state_listener.hpp>
17 
18 namespace restinio
19 {
20 
21 namespace impl
22 {
23 
25 {
26 
27 /*!
28  * @brief A class for holding actual state listener.
29  *
30  * This class holds shared pointer to actual state listener object and
31  * provides actual call_state_listener() implementation.
32  *
33  * @since v.0.5.1
34  */
35 template< typename Listener >
37 {
39 
40  template< typename Settings >
42  const Settings & settings )
44  {}
45 
46  template< typename Lambda >
47  void
48  call_state_listener( Lambda && lambda ) const noexcept
49  {
51  }
52 };
53 
54 /*!
55  * @brief A specialization of state_listener_holder for case of
56  * noop_listener.
57  *
58  * This class doesn't hold anything and doesn't do anything.
59  *
60  * @since v.0.5.1
61  */
62 template<>
64 {
65  template< typename Settings >
66  state_listener_holder_t( const Settings & ) { /* nothing to do */ }
67 
68  template< typename Lambda >
69  void
70  call_state_listener( Lambda && /*lambda*/ ) const noexcept
71  {
72  /* nothing to do */
73  }
74 };
75 
76 } /* namespace connection_settings_details */
77 
78 //
79 // connection_settings_t
80 //
81 
82 //! Parameters shared between connections.
83 /*!
84  Each connection has access to common params and
85  server-agent throught this object.
86 */
87 template < typename Traits >
91  typename Traits::connection_state_listener_t >
92 {
93  using timer_manager_t = typename Traits::timer_manager_t;
95  using request_handler_t = typename Traits::request_handler_t;
96  using logger_t = typename Traits::logger_t;
97 
98  using connection_state_listener_holder_t =
100  typename Traits::connection_state_listener_t >;
101 
102  connection_settings_t( const connection_settings_t & ) = delete;
103  connection_settings_t( const connection_settings_t && ) = delete;
104  connection_settings_t & operator = ( const connection_settings_t & ) = delete;
106 
107  template < typename Settings >
109  Settings && settings,
110  http_parser_settings parser_settings,
111  timer_manager_handle_t timer_manager )
123  , m_logger{ settings.logger() }
125  {
126  if( !m_timer_manager )
127  throw exception_t{ "timer manager not set" };
128  }
129 
130  //! Request handler factory.
132 
133  //! Parser settings.
134  /*!
135  Parsing settings are common for each connection.
136  */
138 
139  //! Params from server_settings_t.
140  //! \{
142 
145 
148 
151 
153 
155  //! \}
156 
157  //! Create new timer guard.
158  auto
160  {
161  return m_timer_manager->create_timer_guard();
162  }
163 
164  private:
165 
166  //! Timer factory for timout guards.
168 };
169 
170 template < typename Traits >
173 
174 } /* namespace impl */
175 
176 } /* namespace restinio */
connection_settings_t(Settings &&settings, http_parser_settings parser_settings, timer_manager_handle_t timer_manager)
std::unique_ptr< request_handler_t > m_request_handler
Request handler factory.
std::chrono::steady_clock::duration m_write_http_response_timelimit
std::chrono::steady_clock::duration m_handle_request_timeout
connection_settings_t & operator=(connection_settings_t &&)=delete
timer_manager_handle_t m_timer_manager
Timer factory for timout guards.
connection_settings_t(const connection_settings_t &&)=delete
const std::unique_ptr< logger_t > m_logger
Parameters shared between connections.
connection_settings_t(const connection_settings_t &)=delete
std::size_t m_buffer_size
Params from server_settings_t.
connection_settings_t & operator=(const connection_settings_t &)=delete
std::chrono::steady_clock::duration m_read_next_http_message_timelimit
auto create_timer_guard()
Create new timer guard.
const http_parser_settings m_parser_settings
Parser settings.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container &params, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...
Definition: value_or.hpp:64