RESTinio
|
Helper class for running an existing HTTP-server on a thread pool without blocking the current thread. More...
#include <http_server_run.hpp>
Public Member Functions | |
on_pool_runner_t (const on_pool_runner_t &)=delete | |
on_pool_runner_t (on_pool_runner_t &&)=delete | |
on_pool_runner_t (std::size_t pool_size, Http_Server &server) | |
Initializing constructor. More... | |
template<typename On_Ok_Callback , typename On_Error_Callback > | |
void | start (On_Ok_Callback &&on_ok, On_Error_Callback &&on_error) |
Start the server with callbacks that will be called on success or failure. More... | |
void | start () |
Start the server. More... | |
bool | started () const noexcept |
Is server started. More... | |
void | stop () noexcept |
Stop the server. More... | |
void | wait () noexcept |
Wait for full stop of the server. More... | |
Private Attributes | |
Http_Server & | m_server |
HTTP-server to be run. More... | |
impl::ioctx_on_thread_pool_t< impl::external_io_context_for_thread_pool_t > | m_pool |
Thread pool for running the server. More... | |
Helper class for running an existing HTTP-server on a thread pool without blocking the current thread.
Usage of run() functions has some drawbacks. For example, the current thread on that run() is called, will be blocked until run() returns.
Sometimes it is not appropriate and leads to tricks like that:
Writing such code is a boring and error-prone task. The class on_pool_runner_t can be used instead:
Moreover the code at point (1) in the example above it not necessary because on_pool_runner_t automatically stops the server in the destructor.
Definition at line 746 of file http_server_run.hpp.
|
delete |
|
delete |
|
inline |
Initializing constructor.
pool_size | Size of thread pool. |
server | Server instance to be run. NOTE. This reference must be valid for all life-time of on_pool_runner instance. |
Definition at line 760 of file http_server_run.hpp.
|
inline |
Start the server.
It just a shorthand for a version of start
method with callbacks where all callbacks to nothing.
Definition at line 855 of file http_server_run.hpp.
|
inline |
Start the server with callbacks that will be called on success or failure.
The on_ok should be a function/functor with the format:
The on_error should be a function/functor with the format:
Usage example:
on_ok | A callback to be called if HTTP-server started successfully. |
on_error | A callback to be called if HTTP-server is not started by some reasons. Please note that this callback is passed to http_server_t::open_async() and will be called only for errors detected by open_async() methods. If some error is detected outside of open_async() (for example a failure to start a thread pool) then on_error callback won't be called. |
Definition at line 821 of file http_server_run.hpp.
|
inlinenoexcept |
Is server started.
Definition at line 864 of file http_server_run.hpp.
|
inlinenoexcept |
Stop the server.
Definition at line 874 of file http_server_run.hpp.
|
inlinenoexcept |
Wait for full stop of the server.
Definition at line 903 of file http_server_run.hpp.
|
private |
Thread pool for running the server.
Definition at line 753 of file http_server_run.hpp.
|
private |
HTTP-server to be run.
Definition at line 749 of file http_server_run.hpp.