14 #include <restinio/asio_include.hpp> 16 #include <restinio/timer_common.hpp> 26 class asio_timer_manager_t
final 27 :
public std::enable_shared_from_this< asio_timer_manager_t >
31 asio_ns::io_context & io_context,
32 std::chrono::steady_clock::duration check_period )
38 class timer_guard_t
final 42 asio_ns::io_context & io_context,
43 std::chrono::steady_clock::duration check_period )
50 schedule( tcp_connection_ctx_weak_handle_t weak_handle )
52 m_operation_timer.expires_after( m_check_period );
53 m_operation_timer.async_wait(
54 [ weak_handle = std::move( weak_handle ) ](
const auto & ec ){
57 if(
auto h = weak_handle.lock() )
59 h->check_timeout( h );
69 m_operation_timer.cancel();
82 return timer_guard_t{ m_io_context, m_check_period };
88 void stop()
const noexcept {}
91 struct factory_t
final 98 factory_t( std::chrono::steady_clock::duration check_period )
noexcept 104 create( asio_ns::io_context & io_context )
const 106 return std::make_shared< asio_timer_manager_t >( io_context, m_check_period );
asio_timer_manager_t(asio_ns::io_context &io_context, std::chrono::steady_clock::duration check_period)
void cancel()
Cancel timeout guard if any.
asio_ns::io_context & m_io_context
An instanse of io_context to work with.
timer_guard_t(asio_ns::io_context &io_context, std::chrono::steady_clock::duration check_period)
factory_t(std::chrono::steady_clock::duration check_period) noexcept
void start() const noexcept
const std::chrono::steady_clock::duration m_check_period
Check period for timer events.
const std::chrono::steady_clock::duration m_check_period
timer_guard_t create_timer_guard() const
Create guard for connection.
asio_ns::steady_timer m_operation_timer
auto create(asio_ns::io_context &io_context) const
Create an instance of timer manager.
void stop() const noexcept
void schedule(tcp_connection_ctx_weak_handle_t weak_handle)
Schedule timeouts check invocation.
const std::chrono::steady_clock::duration m_check_period
Check period for timer events.
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 ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...