|
Evo C++ Library v0.5.1
|
#include <evo/ioasync_server.h>

Async I/O server for receiving and handling requests.
This is a template class that uses a ProtocolServer (T) which implements the server request handling via async I/O event methods.
ProtocolServer is usually also a template class that implements the protocol and uses a user-defined, protocol-specific event-handlerSee Server section in: Asynchronous I/O
The ProtocolServer (T) must define this nested type:
T::Handler: An event handler inheriting AsyncServerHandler (directly or indirectly) and implementing protocol-specific event methodsThe ProtocolServer (T) must implement these event methods:
N bytes): call buffers.read_fixed(), and if that fails (i.e. returns false):fixed_size (out param) to the desired read size and return trueon_read_fixed() will be called when enough data arriveson_read_fixed() event methodfixed_size unless buffers.read_fixed() has been called and returned falseon_read() when reading fixed-size dataon_read() set a fixed_sizedata param will not be valid after this returnsThe ProtocolServer (T) must define this constant:
MIN_INITIAL_READ: Minimum size (in bytes) needed before calling on_read() the first time for a request, 0 for any amount | T | ProtocolServer type to use (see above) |
Classes | |
| struct | Stats |
Public Types | |
| typedef ProtocolServer::Handler::DeferredContext | DeferredContext |
| typedef ProtocolServer::Handler::Global | Global |
| typedef T | ProtocolServer |
| typedef ProtocolServer::Handler::Shared | Shared |
| typedef AsyncServer< ProtocolServer > | This |
Public Member Functions | |
| AsyncServer () | |
| Constructor. More... | |
| Global & | get_global () |
| Get reference to global data used by all requests and all threads in this server. More... | |
| bool | run (IoSocket::Handle listener) |
| Run server event handling and handle connections until shutdown. More... | |
| bool | run (Socket &listener) |
| Run server and handle connections until shutdown. More... | |
| bool | runlocal () |
| Run the event-loop locally in current thread until all pending requests are handled (client only). More... | |
| virtual void | set_logger (LoggerBase *newlogger) |
| Set logger to use. More... | |
| void | set_timeout (ulong read_timeout_ms=0, ulong write_timeout_ms=0) |
| Set read/write timeouts to use. More... | |
| bool | set_timer (OnTimer &on_timer, ulong msec) |
| Activate timer so it expires after given time elapses. More... | |
| void | shutdown () |
| Shut down server. More... | |
Public Attributes | |
| LoggerPtr | logger |
| Logger for protocol and debug messages, set to enable logging – see set_logger() More... | |
Protected Member Functions | |
| virtual bool | check_client_active () |
| Called during client event-loop to check whether any client requests are active (client only). More... | |
| void | init () |
| Initialize event-loop. More... | |
| void | init_attach (AsyncBase &parent) |
| Initialize and attach to a parent event-loop. More... | |
| bool | run_eventloop () |
| Run event loop and process all events and repeat until shutdown. More... | |
| bool | run_eventloop_once () |
| Run event loop with one pass and process all events. More... | |
Static Protected Member Functions | |
| static struct timeval * | get_timeout_ptr (struct timeval &out, ulong ms) |
| Get timeval struct pointer from timeout in milliseconds. More... | |
Protected Attributes | |
| AsyncBase * | child_base_ |
| Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none. More... | |
| AsyncEventLoop * | evloop_ |
| Event loop pointer, either owned by this or a parent. More... | |
| bool | local_ |
| Whether event-loop is local (same thread), false if separate thread. More... | |
| AsyncBase * | parent_base_ |
| Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer) More... | |
| ulong | read_timeout_ms_ |
| Socket read timeout in milliseconds, 0 for none (never timeout) More... | |
| ulong | write_timeout_ms_ |
| Socket write timeout in milliseconds, 0 for none (never timeout) More... | |
| typedef ProtocolServer::Handler::DeferredContext DeferredContext |
| typedef ProtocolServer::Handler::Global Global |
| typedef T ProtocolServer |
| typedef ProtocolServer::Handler::Shared Shared |
| typedef AsyncServer<ProtocolServer> This |
|
inline |
Constructor.
|
inlineprotectedvirtualinherited |
Called during client event-loop to check whether any client requests are active (client only).
|
inline |
Get reference to global data used by all requests and all threads in this server.
|
inlinestaticprotectedinherited |
Get timeval struct pointer from timeout in milliseconds.
| out | Struct to store timeout |
| ms | Time in milliseconds to use |
out, or NULL if ms is 0
|
inlineprotectedinherited |
Initialize event-loop.
|
inlineprotectedinherited |
Initialize and attach to a parent event-loop.
| parent | Parent AsyncBase to attach to |
|
inline |
Run server event handling and handle connections until shutdown.
Shared::on_init()) and runs the event-loop to accept and handle connections| listener | Listener socket handle to accept connections on |
Shared::on_init() or internal error)
|
inline |
Run server and handle connections until shutdown.
| listener | Listener socket to accept connections on |
Shared::on_init() or internal error)
|
inlineprotectedinherited |
Run event loop and process all events and repeat until shutdown.
|
inlineprotectedinherited |
Run event loop with one pass and process all events.
|
inlineinherited |
Run the event-loop locally in current thread until all pending requests are handled (client only).
|
inlinevirtualinherited |
Set logger to use.
| newlogger | Pointer to logger to set, NULL for none (no logging) |
|
inlineinherited |
|
inlineinherited |
Activate timer so it expires after given time elapses.
| on_timer | Timer to use |
| msec | Expiration time in milliseconds |
|
inline |
Shut down server.
|
protectedinherited |
Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none.
|
protectedinherited |
Event loop pointer, either owned by this or a parent.
|
protectedinherited |
Whether event-loop is local (same thread), false if separate thread.
|
inherited |
Logger for protocol and debug messages, set to enable logging – see set_logger()
|
protectedinherited |
Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer)
|
protectedinherited |
Socket read timeout in milliseconds, 0 for none (never timeout)
|
protectedinherited |
Socket write timeout in milliseconds, 0 for none (never timeout)
1.8.13