Evo C++ Library v0.5.1
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
AsyncBase Class Reference

#include <evo/ioasync_base.h>

Inheritance diagram for AsyncBase:
Inheritance graph
[legend]

Detailed Description

Base class for Async I/O.

Classes

struct  OnTimer
 Timer expired event. More...
 

Public Member Functions

 AsyncBase ()
 Constructor. More...
 
virtual ~AsyncBase ()
 Destructor. 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...
 

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

AsyncBasechild_base_
 Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none. More...
 
AsyncEventLoopevloop_
 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...
 
AsyncBaseparent_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...
 

Constructor & Destructor Documentation

◆ AsyncBase()

AsyncBase ( )
inline

Constructor.

◆ ~AsyncBase()

virtual ~AsyncBase ( )
inlinevirtual

Destructor.

  • This detaches from parent, if applicable

Member Function Documentation

◆ check_client_active()

virtual bool check_client_active ( )
inlineprotectedvirtual

Called during client event-loop to check whether any client requests are active (client only).

  • This is used to determine if all client requests were handled
  • Only AsyncClient should override this, AsyncServer should leave the default
Returns
Whether any client requests are active, true if a request is in progress (waiting for response or write is pending)

◆ get_timeout_ptr()

static struct timeval* get_timeout_ptr ( struct timeval &  out,
ulong  ms 
)
inlinestaticprotected

Get timeval struct pointer from timeout in milliseconds.

Parameters
outStruct to store timeout
msTime in milliseconds to use
Returns
Pointer to out, or NULL if ms is 0

◆ init()

void init ( )
inlineprotected

Initialize event-loop.

  • Ignored if already initialized

◆ init_attach()

void init_attach ( AsyncBase parent)
inlineprotected

Initialize and attach to a parent event-loop.

  • Ignored if already initialized
Parameters
parentParent AsyncBase to attach to

◆ run_eventloop()

bool run_eventloop ( )
inlineprotected

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 ( )
inlineprotected

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()

bool runlocal ( )
inline

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()

virtual void set_logger ( LoggerBase newlogger)
inlinevirtual

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
newloggerPointer to logger to set, NULL for none (no logging)

◆ set_timeout()

void set_timeout ( ulong  read_timeout_ms = 0,
ulong  write_timeout_ms = 0 
)
inline

Set read/write timeouts to use.

Parameters
read_timeout_msSocket read timeout in milliseconds, 0 for none (never timeout)
write_timeout_msSocket write timeout in milliseconds, 0 for none (never timeout)

◆ set_timer()

bool set_timer ( OnTimer on_timer,
ulong  msec 
)
inline

Activate timer so it expires after given time elapses.

Parameters
on_timerTimer to use
msecExpiration time in milliseconds
Returns
Whether successful, false on internal error

Member Data Documentation

◆ child_base_

AsyncBase* child_base_
protected

Pointer to child in AsyncBase chain (always an AsyncClient), NULL for none.

◆ evloop_

AsyncEventLoop* evloop_
protected

Event loop pointer, either owned by this or a parent.

◆ local_

bool local_
protected

Whether event-loop is local (same thread), false if separate thread.

◆ logger

LoggerPtr logger

Logger for protocol and debug messages, set to enable logging – see set_logger()

◆ parent_base_

AsyncBase* parent_base_
protected

Pointer to parent in AsyncBase chain, NULL if this is the main parent (and owns evloop_ pointer)

◆ read_timeout_ms_

ulong read_timeout_ms_
protected

Socket read timeout in milliseconds, 0 for none (never timeout)

◆ write_timeout_ms_

ulong write_timeout_ms_
protected

Socket write timeout in milliseconds, 0 for none (never timeout)


The documentation for this class was generated from the following file: