RESTinio
|
Class for http-server. More...
#include <http_server.hpp>
Public Member Functions | |
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>()( *(static_cast<server_settings_t<Traits>*>(nullptr))))> | |
http_server_t (io_context_holder_t io_context, Configurator &&configurator) | |
virtual | ~http_server_t () |
It is allowed to inherit from http_server_t. More... | |
asio_ns::io_context & | io_context () noexcept |
Get io_context on which server runs. More... | |
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. More... | |
void | open_sync () |
Start server. More... | |
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. More... | |
void | close_sync () |
Stop server. More... | |
Private Types | |
enum | running_state_t { running_state_t::not_running, running_state_t::running } |
State of server. More... | |
using | connection_settings_t = impl::connection_settings_t< Traits > |
using | connection_factory_t = impl::connection_factory_t< Traits > |
using | acceptor_t = impl::acceptor_t< Traits > |
using | timer_manager_t = typename Traits::timer_manager_t |
using | timer_manager_handle_t = std::shared_ptr< timer_manager_t > |
Private Member Functions | |
void | call_cleanup_functor () noexcept |
Call a cleanup functor if it is defined. More... | |
Static Private Member Functions | |
template<typename Callback > | |
static void | call_nothrow_cb (Callback &&cb) noexcept |
Call callback and terminate the application if callback throws. More... | |
Private Attributes | |
io_context_shared_ptr_t | m_io_context |
A wrapper for asio io_context where server is running. More... | |
cleanup_functor_t | m_cleanup_functor |
An optional user's cleanup functor. More... | |
std::shared_ptr< acceptor_t > | m_acceptor |
Acceptor for new connections. More... | |
timer_manager_handle_t | m_timer_manager |
Timer manager object. More... | |
running_state_t | m_running_state { running_state_t::not_running } |
Server state. More... | |
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:
Async way for starting and stopping a http_server can be used if http_server_t::open_async() and http_server_t::open_async() can be called from any other thread. For example:
Definition at line 168 of file http_server.hpp.
|
private |
Definition at line 172 of file http_server.hpp.
|
private |
Definition at line 171 of file http_server.hpp.
|
private |
Definition at line 170 of file http_server.hpp.
|
private |
Definition at line 174 of file http_server.hpp.
|
private |
Definition at line 173 of file http_server.hpp.
|
strongprivate |
|
inline |
Definition at line 178 of file http_server.hpp.
|
inline |
Definition at line 213 of file http_server.hpp.
|
inlinevirtual |
It is allowed to inherit from http_server_t.
Definition at line 223 of file http_server.hpp.
|
inlineprivatenoexcept |
Call a cleanup functor if it is defined.
Definition at line 357 of file http_server.hpp.
|
inlinestaticprivatenoexcept |
Call callback and terminate the application if callback throws.
Definition at line 368 of file http_server.hpp.
|
inline |
Closes server in async way.
Definition at line 286 of file http_server.hpp.
|
inline |
Stop server.
If server was stopped successfully then function returns, otherwise it throws.
Definition at line 313 of file http_server.hpp.
|
inlinenoexcept |
Get io_context on which server runs.
Definition at line 230 of file http_server.hpp.
|
inline |
Starts server in async way.
Definition at line 240 of file http_server.hpp.
|
inline |
Start server.
If server was started successfully then function returns, otherwise it throws.
Definition at line 267 of file http_server.hpp.
|
private |
Acceptor for new connections.
Definition at line 332 of file http_server.hpp.
|
private |
An optional user's cleanup functor.
Definition at line 329 of file http_server.hpp.
|
private |
A wrapper for asio io_context where server is running.
Definition at line 326 of file http_server.hpp.
|
private |
Server state.
Definition at line 345 of file http_server.hpp.
|
private |
Timer manager object.
Definition at line 335 of file http_server.hpp.