|
| | Service (int threads=1, bool pool=false) |
| | Initialize Asio service with single or multiple working threads.
|
| | Service (const std::shared_ptr< asio::io_context > &io_context, bool strands=false) |
| | Initialize Asio service manually with a given Asio IO context.
|
| | Service (const Service &)=delete |
| | Service (Service &&)=delete |
| virtual | ~Service ()=default |
| Service & | operator= (const Service &)=delete |
| Service & | operator= (Service &&)=delete |
| size_t | threads () const noexcept |
| | Get the number of working threads.
|
| bool | IsStrandRequired () const noexcept |
| | Is the service required strand to serialized handler execution?
|
| bool | IsPolling () const noexcept |
| | Is the service started with polling loop mode?
|
| bool | IsStarted () const noexcept |
| | Is the service started?
|
| virtual bool | Start (bool polling=false) |
| | Start the service.
|
| virtual bool | Stop () |
| | Stop the service.
|
| virtual bool | Restart () |
| | Restart the service.
|
| virtual std::shared_ptr< asio::io_context > & | GetAsioContext () noexcept |
| | Get the next available Asio IO context.
|
| template<typename CompletionHandler> |
| | ASIO_INITFN_RESULT_TYPE (CompletionHandler, void()) Dispatch(ASIO_MOVE_ARG(CompletionHandler) handler) |
| | Dispatch the given handler.
|
| template<typename CompletionHandler> |
| | ASIO_INITFN_RESULT_TYPE (CompletionHandler, void()) Post(ASIO_MOVE_ARG(CompletionHandler) handler) |
| | Post the given handler.
|
Asio service.
Asio service is used to host all clients/servers based on Asio C++ library. It is implemented based on Asio C++ Library and use one or more threads to perform all asynchronous IO operations and communications.
There are three ways to initialize Asio service:
1) Service(threads, false) - initialize a new Asio service with io-context- per-thread design. In this case each Asio IO context will be bounded to its own working thread and all handlers will be dispatched sequentially without strands making the code clean and easy to maintain.
2) Service(threads, true) - initialize a new Asio service with thread-pool design. In this case single Asio IO context will be bounded to all threads in pool, but strands will be required to serialize handler execution.
3) Service(service, true | false) - initialize a new Asio service using the existing Asio IO context instance with required strands flag. Strands are required for serialized handler execution when single Asio IO context used in thread pool.
Thread-safe.
https://think-async.com
Definition at line 53 of file service.h.
template<typename CompletionHandler>
| CppServer::Asio::Service::ASIO_INITFN_RESULT_TYPE |
( |
CompletionHandler | , |
|
|
void() | ) |
|
inline |
Dispatch the given handler.
The given handler may be executed immediately if this function is called from IO context thread. Otherwise it will be enqueued to the IO context pending operations queue.
Method takes a handler to dispatch as a parameter and returns async result of the handler.
Definition at line 121 of file service.h.