Loading...
Searching...
No Matches
connection_settings.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <http_parser.h>
#include <restinio/connection_state_listener.hpp>
#include <restinio/incoming_http_msg_limits.hpp>
#include <restinio/utils/suppress_exceptions.hpp>
#include <memory>
#include <chrono>
namespace restinio
{
namespace impl
{
namespace connection_settings_details
{
template< typename Listener >
struct state_listener_holder_t
{
std::shared_ptr< Listener > m_connection_state_listener;
template< typename Settings >
state_listener_holder_t(
const Settings & settings )
: m_connection_state_listener{ settings.connection_state_listener() }
{}
template< typename Lambda >
void
call_state_listener( Lambda && lambda ) const
{
m_connection_state_listener->state_changed( lambda() );
}
template< typename Lambda >
void
call_state_listener_suppressing_exceptions(
Lambda && lambda ) const noexcept
{
restinio::utils::suppress_exceptions_quietly( [&] {
m_connection_state_listener->state_changed( lambda() );
} );
}
};
template<>
struct state_listener_holder_t< connection_state::noop_listener_t >
{
template< typename Settings >
state_listener_holder_t( const Settings & ) { /* nothing to do */ }
template< typename Lambda >
void
call_state_listener( Lambda && /*lambda*/ ) const noexcept
{
/* nothing to do */
}
template< typename Lambda >
void
call_state_listener_suppressing_exceptions(
Lambda && /*lambda*/ ) const noexcept
{
/* nothing to do */
}
};
} /* namespace connection_settings_details */
//
// connection_settings_t
//
template < typename Traits >
struct connection_settings_t final
: public std::enable_shared_from_this< connection_settings_t< Traits > >
, public connection_settings_details::state_listener_holder_t<
typename Traits::connection_state_listener_t >
{
using timer_manager_t = typename Traits::timer_manager_t;
using timer_manager_handle_t = std::shared_ptr< timer_manager_t >;
using request_handler_t = request_handler_type_from_traits_t< Traits >;
using logger_t = typename Traits::logger_t;
using connection_state_listener_holder_t =
connection_settings_details::state_listener_holder_t<
typename Traits::connection_state_listener_t >;
using extra_data_factory_handle_t =
std::shared_ptr< typename Traits::extra_data_factory_t >;
connection_settings_t( const connection_settings_t & ) = delete;
connection_settings_t( const connection_settings_t && ) = delete;
connection_settings_t & operator = ( const connection_settings_t & ) = delete;
connection_settings_t & operator = ( connection_settings_t && ) = delete;
template < typename Settings >
connection_settings_t(
Settings && settings,
http_parser_settings parser_settings,
timer_manager_handle_t timer_manager )
: connection_state_listener_holder_t{ settings }
, m_request_handler{ settings.request_handler() }
, m_parser_settings{ parser_settings }
, m_buffer_size{ settings.buffer_size() }
, m_incoming_http_msg_limits{ settings.incoming_http_msg_limits() }
, m_read_next_http_message_timelimit{
settings.read_next_http_message_timelimit() }
, m_write_http_response_timelimit{
settings.write_http_response_timelimit() }
, m_handle_request_timeout{
settings.handle_request_timeout() }
, m_max_pipelined_requests{ settings.max_pipelined_requests() }
, m_logger{ settings.logger() }
, m_timer_manager{ std::move( timer_manager ) }
, m_extra_data_factory{ settings.giveaway_extra_data_factory() }
{
if( !m_timer_manager )
throw exception_t{ "timer manager not set" };
if( !m_extra_data_factory )
throw exception_t{ "extra_data_factory is nullptr" };
}
std::unique_ptr< request_handler_t > m_request_handler;
const http_parser_settings m_parser_settings;
std::size_t m_buffer_size;
const incoming_http_msg_limits_t m_incoming_http_msg_limits;
std::chrono::steady_clock::duration
m_read_next_http_message_timelimit{ std::chrono::seconds( 60 ) };
std::chrono::steady_clock::duration
m_write_http_response_timelimit{ std::chrono::seconds( 5 ) };
std::chrono::steady_clock::duration
m_handle_request_timeout{ std::chrono::seconds( 10 ) };
std::size_t m_max_pipelined_requests;
const std::unique_ptr< logger_t > m_logger;
auto
create_timer_guard()
{
return m_timer_manager->create_timer_guard();
}
RESTINIO_NODISCARD
auto &
extra_data_factory() const noexcept
{
return *m_extra_data_factory;
}
private:
timer_manager_handle_t m_timer_manager;
extra_data_factory_handle_t m_extra_data_factory;
};
template < typename Traits >
using connection_settings_handle_t =
std::shared_ptr< connection_settings_t< Traits > >;
} /* namespace impl */
} /* namespace restinio */
restinio::exception_t
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
restinio::incoming_http_msg_limits_t
A type of holder of limits related to an incoming HTTP message.
Definition: incoming_http_msg_limits.hpp:69
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:36
connection_state_listener.hpp
Stuff related to connection state listeners.
incoming_http_msg_limits.hpp
Stuff related to limits of an incoming HTTP message.
restinio::impl::connection_settings_handle_t
std::shared_ptr< connection_settings_t< Traits > > connection_settings_handle_t
Definition: connection_settings.hpp:235
restinio::utils::suppress_exceptions_quietly
void suppress_exceptions_quietly(Lambda &&lambda) noexcept
Helper function for execution a block of code with suppression of any exceptions raised inside that b...
Definition: suppress_exceptions.hpp:135
restinio
Definition: asio_include.hpp:21
restinio::request_handler_type_from_traits_t
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:379
std
STL namespace.
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::call_state_listener
void call_state_listener(Lambda &&) const noexcept
Definition: connection_settings.hpp:84
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::state_listener_holder_t
state_listener_holder_t(const Settings &)
Definition: connection_settings.hpp:80
restinio::impl::connection_settings_details::state_listener_holder_t< connection_state::noop_listener_t >::call_state_listener_suppressing_exceptions
void call_state_listener_suppressing_exceptions(Lambda &&) const noexcept
Definition: connection_settings.hpp:91
restinio::impl::connection_settings_details::state_listener_holder_t
A class for holding actual state listener.
Definition: connection_settings.hpp:41
restinio::impl::connection_settings_details::state_listener_holder_t::call_state_listener
void call_state_listener(Lambda &&lambda) const
Definition: connection_settings.hpp:52
restinio::impl::connection_settings_details::state_listener_holder_t::call_state_listener_suppressing_exceptions
void call_state_listener_suppressing_exceptions(Lambda &&lambda) const noexcept
Definition: connection_settings.hpp:59
restinio::impl::connection_settings_details::state_listener_holder_t::state_listener_holder_t
state_listener_holder_t(const Settings &settings)
Definition: connection_settings.hpp:45
restinio::impl::connection_settings_details::state_listener_holder_t::m_connection_state_listener
std::shared_ptr< Listener > m_connection_state_listener
Definition: connection_settings.hpp:42
restinio::impl::connection_settings_t
Parameters shared between connections.
Definition: connection_settings.hpp:114
restinio::impl::connection_settings_t::m_buffer_size
std::size_t m_buffer_size
Params from server_settings_t.
Definition: connection_settings.hpp:178
restinio::impl::connection_settings_t::m_max_pipelined_requests
std::size_t m_max_pipelined_requests
Definition: connection_settings.hpp:194
restinio::impl::connection_settings_t::extra_data_factory
RESTINIO_NODISCARD auto & extra_data_factory() const noexcept
Get a reference to extra-data-factory object.
Definition: connection_settings.hpp:213
restinio::impl::connection_settings_t::logger_t
typename Traits::logger_t logger_t
Definition: connection_settings.hpp:120
restinio::impl::connection_settings_t::request_handler_t
request_handler_type_from_traits_t< Traits > request_handler_t
Definition: connection_settings.hpp:118
restinio::impl::connection_settings_t::operator=
connection_settings_t & operator=(const connection_settings_t &)=delete
restinio::impl::connection_settings_t::extra_data_factory_handle_t
std::shared_ptr< typename Traits::extra_data_factory_t > extra_data_factory_handle_t
An alias for shared-pointer to extra-data-factory.
Definition: connection_settings.hpp:132
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(Settings &&settings, http_parser_settings parser_settings, timer_manager_handle_t timer_manager)
Definition: connection_settings.hpp:140
restinio::impl::connection_settings_t::m_parser_settings
const http_parser_settings m_parser_settings
Parser settings.
Definition: connection_settings.hpp:174
restinio::impl::connection_settings_t::m_timer_manager
timer_manager_handle_t m_timer_manager
Timer factory for timout guards.
Definition: connection_settings.hpp:220
restinio::impl::connection_settings_t::m_handle_request_timeout
std::chrono::steady_clock::duration m_handle_request_timeout
Definition: connection_settings.hpp:192
restinio::impl::connection_settings_t::timer_manager_handle_t
std::shared_ptr< timer_manager_t > timer_manager_handle_t
Definition: connection_settings.hpp:116
restinio::impl::connection_settings_t::m_request_handler
std::unique_ptr< request_handler_t > m_request_handler
Request handler factory.
Definition: connection_settings.hpp:168
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(const connection_settings_t &)=delete
restinio::impl::connection_settings_t::m_logger
const std::unique_ptr< logger_t > m_logger
Definition: connection_settings.hpp:196
restinio::impl::connection_settings_t::connection_settings_t
connection_settings_t(const connection_settings_t &&)=delete
restinio::impl::connection_settings_t::timer_manager_t
typename Traits::timer_manager_t timer_manager_t
Definition: connection_settings.hpp:115
restinio::impl::connection_settings_t::m_extra_data_factory
extra_data_factory_handle_t m_extra_data_factory
A factory for instances of extra-data incorporated into a request.
Definition: connection_settings.hpp:230
restinio::impl::connection_settings_t::m_write_http_response_timelimit
std::chrono::steady_clock::duration m_write_http_response_timelimit
Definition: connection_settings.hpp:189
restinio::impl::connection_settings_t::m_incoming_http_msg_limits
const incoming_http_msg_limits_t m_incoming_http_msg_limits
Definition: connection_settings.hpp:183
restinio::impl::connection_settings_t::m_read_next_http_message_timelimit
std::chrono::steady_clock::duration m_read_next_http_message_timelimit
Definition: connection_settings.hpp:186
restinio::impl::connection_settings_t::create_timer_guard
auto create_timer_guard()
Create new timer guard.
Definition: connection_settings.hpp:201
suppress_exceptions.hpp
Utilities for suppressing exceptions from some code block.
const
#define const
Definition: zconf.h:230