#include <evo/ioasync_client.h>
template<class T, class Q>
class evo::AsyncClient< T, Q >
Template class for an async I/O client.
- This is inherited by a client implementing a given protocol – not used directly
- See Asynchronous I/O
- Template Parameters
-
T | Protocol handler type, which must inherit from AsyncClient |
Q | Response queue type that works with the protocol used
- Must have
null() and set() methods, and must default construct as null
|
|
static struct timeval * | get_timeout_ptr (struct timeval &out, ulong ms) |
| Get timeval struct pointer from timeout in milliseconds. More...
|
|
◆ ProtocolHandler
Derived protocol hander type (must inherit from AsyncClient)
◆ QueueItem
Response queue item type.
◆ This
◆ State
Client state.
Enumerator |
---|
sNONE | No connection.
|
sCONNECTING | Connection in progress.
|
sCONNECTED | Connected.
|
◆ AsyncClient()
Constructor.
- Parameters
-
max_queue_size | Max size for pending response queue |
max_read_size | Max read buffer size, 0 for unlimited – this is used to limit the read buffer size |
◆ ~AsyncClient()
◆ attach_to()
Attach to a parent AsyncClient or AsyncServer and use the same event-loop as the parent.
- This must be called before any
connect*()
method, otherwise this is ignored
- Parameters
-
parent | Parent to attach to |
- Returns
- This
◆ close()
Close connection.
- This must not be called from an event handler
◆ connect_ip()
bool connect_ip |
( |
const char * |
host, |
|
|
ushort |
port, |
|
|
int |
family = AF_INET |
|
) |
| |
|
inline |
Start IP connection.
- This is non-blocking and returns immediately while connecting
◆ get_id()
Get current client ID.
- Returns
- Client ID
◆ get_state()
State get_state |
( |
| ) |
const |
|
inline |
Get current state.
- Returns
- Current state
◆ get_timeout_ptr()
static struct timeval* get_timeout_ptr |
( |
struct timeval & |
out, |
|
|
ulong |
ms |
|
) |
| |
|
inlinestaticprotectedinherited |
Get timeval struct pointer from timeout in milliseconds.
- Parameters
-
out | Struct to store timeout |
ms | Time in milliseconds to use |
- Returns
- Pointer to
out
, or NULL if ms
is 0
◆ init()
Initialize event-loop.
- Ignored if already initialized
◆ init_attach()
Initialize and attach to a parent event-loop.
- Ignored if already initialized
- Parameters
-
◆ run_eventloop()
Run event loop and process all events and repeat until shutdown.
- Returns
- Whether successful, false on internal error
◆ run_eventloop_once()
bool run_eventloop_once |
( |
| ) |
|
|
inlineprotectedinherited |
Run event loop with one pass and process all events.
- This waits until some events are active then processes all active events and returns
- Returns
- Whether successful, false on internal error
◆ runlocal()
Run the event-loop locally in current thread until all pending requests are handled (client only).
- This blocks while client requests are pending
- This returns false immediately if this does not own an event-loop (i.e. was attached to a parent) – only the top parent can run an event-loop
- Returns
- Whether successful, false if attached to another AsyncBase or on internal error
◆ set_logger()
Set logger to use.
- If set, a logger shows low-level details and error information from the framework
- The logger pointer must remain valid as long as it's referenced here
- Parameters
-
newlogger | Pointer to logger to set, NULL for none (no logging) |
◆ set_on_connect()
Set general handler to call when a connection is established.
- Parameters
-
- Returns
- This
◆ set_on_error()
Set general handler to call when an unexpected error occurs.
- Parameters
-
cb | OnError event to use, NULL for none |
- Returns
- This
◆ set_timeout()
void set_timeout |
( |
ulong |
read_timeout_ms = 0 , |
|
|
ulong |
write_timeout_ms = 0 |
|
) |
| |
|
inlineinherited |
Set read/write timeouts to use.
- Parameters
-
read_timeout_ms | Socket read timeout in milliseconds, 0 for none (never timeout) |
write_timeout_ms | Socket write timeout in milliseconds, 0 for none (never timeout) |
◆ set_timer()
bool set_timer |
( |
OnTimer & |
on_timer, |
|
|
ulong |
msec |
|
) |
| |
|
inlineinherited |
Activate timer so it expires after given time elapses.
- Parameters
-
on_timer | Timer to use |
msec | Expiration time in milliseconds |
- Returns
- Whether successful, false on internal error
◆ child_base_
◆ evloop_
Event loop pointer, either owned by this or a parent.
◆ local_
Whether event-loop is local (same thread), false if separate thread.
◆ logger
◆ parent_base_
Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer)
◆ queue_
Queue where each item represents an expected response from server.
◆ read_timeout_ms_
Socket read timeout in milliseconds, 0 for none (never timeout)
◆ write_timeout_ms_
Socket write timeout in milliseconds, 0 for none (never timeout)
The documentation for this class was generated from the following file: