template<std::size_t Size, typename Extra_Data_Factory = no_extra_data_factory_t>
class restinio::async_chain::fixed_size_chain_t< Size, Extra_Data_Factory >
A holder of fixed-size chain of asynchronous handlers.
- Note
- An instance of that type is intended to be filled with actual schedulers at the creation time. After that new schedulers can't be added to the chain, and old handlers can't be removed from the chain.
Usage example for the case when there is no extra-data in a request object (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):
};
{
...
next( std::move(controller) );
}
{
...
next( std::move(controller) );
}
{
...
}
.address(...)
.port(...)
.request_handler(
headers_checker,
authentificator,
actual_handler )
);
A holder of fixed-size chain of asynchronous handlers.
constexpr schedule_result_t ok() noexcept
Helper function to be used if scheduling was successful.
void next(unique_async_handling_controller_t< Extra_Data_Factory > controller)
Command to try to switch to the next handler in an async chain.
schedule_result_t
Type for return value of a scheduler in a chain.
std::unique_ptr< async_handling_controller_t< Extra_Data_Factory > > unique_async_handling_controller_t
Short alias for unique_ptr to async_handling_controller.
run_on_thread_pool_settings_t< Traits > on_thread_pool(std::size_t pool_size)
A special marker for the case when http_server must be run on an thread pool.
void run(asio_ns::io_context &ioctx, run_on_this_thread_settings_t< Traits > &&settings)
Helper function for running http server until ctrl+c is hit.
traits_t< asio_timer_manager_t, null_logger_t > default_traits_t
details::autodetect_request_handler_type request_handler_t
An instance of fixed_size_chain_t can also be created manually and passed to server's settings by unique_ptr:
auto chain = std::make_unique<restinio::async_chain::fixed_size_chain_t<3>>(
headers_checker, authentificator, actual_handler);
...
restinio::run(
.address(...)
.port(...)
.request_handler(std::move(chain))
);
Usage example for the case when some extra-data is incorporated into a request object (please note that this is simplified example without actual asynchronous code, all schedulers work as synchronous handlers):
struct my_extra_data_factory {
struct request_specific_fields_t {...};
struct user_info_t {...};
using data_t = std::tuple<request_specific_fields_t, user_info_t>;
}
};
3,
extra_data_factory>;
};
using my_unique_controller_t =
using my_request_handle_t = my_unique_controller_t::actual_request_handle_t;
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
...
...
next( std::move(controller) );
}
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
...
...
next( std::move(controller) );
}
my_unique_controller_t controller )
{
const my_request_handle_t req = acceptor->request_handle();
auto & field_values = std::get<my_extra_data_factory::request_specific_fields_t>(req->extra_data());
auto & user_info = std::get<my_extra_data_factory::user_info_t>(req->extra_data());
...
}
.address(...)
.port(...)
.request_handler(
headers_checker,
authentificator,
actual_handler )
);
no_extra_data_factory_t extra_data_factory_t
- Template Parameters
-
Size | The exact number of schedulers in the chain. |
Extra_Data_Factory | The type of extra-data-factory specified in the server's traits. |
- Since
- v.0.7.0
- Examples
- sample/async_chained_handlers/main.cpp.
Definition at line 179 of file fixed_size.hpp.