|
| | http_server_t (const http_server_t &)=delete |
| | http_server_t (http_server_t &&)=delete |
| template<typename D> |
| | http_server_t (io_context_holder_t io_context, basic_server_settings_t< D, Traits > &&settings) |
| template<typename Configurator, typename = decltype( std::declval<Configurator>()( std::declval<server_settings_t<Traits>&>() ) )> |
| | http_server_t (io_context_holder_t io_context, Configurator &&configurator) |
| virtual | ~http_server_t () |
| | It is allowed to inherit from http_server_t.
|
| asio_ns::io_context & | io_context () noexcept |
| | Get io_context on which server runs.
|
| template<typename Server_Open_Ok_CB, typename Server_Open_Error_CB> |
| void | open_async (Server_Open_Ok_CB open_ok_cb, Server_Open_Error_CB open_err_cb) |
| | Starts server in async way.
|
| void | open_sync () |
| | Start server.
|
| template<typename Server_Close_Ok_CB, typename Server_Close_Error_CB> |
| void | close_async (Server_Close_Ok_CB close_ok_cb, Server_Close_Error_CB close_err_cb) |
| | Closes server in async way.
|
| void | close_sync () |
| | Stop server.
|
template<typename Traits = default_traits_t>
class restinio::http_server_t< Traits >
Class for http-server.
With the help of this class one can run a server. Server can be started and stopped in sync or async way.
Please note that it is responsibility of user to provide a working context for http_server. It means that user must call asio::io_context::run() on some work thread (or on several working threads).
Sync way for starting and stopping a http_server can be used only if http_server_t::open_sync() and http_server_t::close_sync() methods are called somewhere inside asio::io_context::run(). For example:
[&]( auto & settings ){
settings
.port( args.port() )
.request_handler(
} );
} };
[&] {
server.open_sync();
} );
asio_ns::io_context & io_context() noexcept
Get io_context on which server runs.
std::shared_ptr< request_t > request_handle_t
An alias for handle for incoming request without additional extra-data.
io_context_holder_t own_io_context()
Function which tells that http_server should create and use its own instance of io_context.
Async way for starting and stopping a http_server can be used if http_server_t::open_async() and http_server_t::close_async() can be called from any other thread. For example:
asio::io_context io_ctx;
[&]( auto & settings ) { ... } };
std::thread server_thread{ [&] {
io_ctx.run();
} };
std::exception_ptr exception_from_open_async;
[]() noexcept {},
[&]( std::exception_ptr ex_ptr ) noexcept {
exception_from_open_async = ex_ptr;
} );
...
server_thread.join();
void open_async(Server_Open_Ok_CB open_ok_cb, Server_Open_Error_CB open_err_cb)
Starts server in async way.
io_context_holder_t external_io_context(asio_ns::io_context &ctx)
Function which tells that http_server should use external instance of io_context and should not contr...
- Examples
- sample/using_external_io_context/main.cpp, and sample/websocket_detailed/main.cpp.
Definition at line 172 of file http_server.hpp.