3es
0.7
|
A utility class for monitoring new connections for a Server
.
More...
#include <3esconnectionmonitor.h>
Public Types | |
enum | Mode { None, Synchronous, Asynchronous } |
Public Member Functions | |
virtual bool | start (Mode mode)=0 |
Starts the monitor listening in the specified mode. More... | |
virtual void | stop ()=0 |
Stops listening for further connections. More... | |
virtual void | join ()=0 |
Called to join the monitor thread. More... | |
virtual bool | isRunning () const =0 |
Returns true if the connection monitor has start. More... | |
virtual Mode | mode () const =0 |
Returns the current running mode. More... | |
virtual int | waitForConnection (unsigned timeoutMs)=0 |
Wait up to timeoutMs milliseconds for a connection. More... | |
virtual void | monitorConnections ()=0 |
Accepts new connections and checks for expired connections, but effects neither in the Server . More... | |
virtual void | setConnectionCallback (void(*callback)(Server &, Connection &, void *), void *user)=0 |
Sets the callback invoked for each new connection. More... | |
virtual void | setConnectionCallback (const std::function< void(Server &, Connection &)> &callback)=0 |
An overload of setConnectionCallback() using the C++11 funtion object. More... | |
virtual void | commitConnections ()=0 |
Migrates new connections to the owning Server and removes expired connections. More... | |
Protected Member Functions | |
virtual | ~ConnectionMonitor () |
Protected virtual destructor. | |
A utility class for monitoring new connections for a Server
.
The monitor manages listening for new connections and expiring old ones. Doing so can be time consuming, so the monitor supports running its own monitor thread. It also supports synchronous operation in case connection monitoring is unnecessary, or unable to be pushed off thread.
Asynchronous mode is activated by calling start()
and stopped with stop()
. Calls to join()
will block until the monitor thread has completed, but should only be called after stop()
has been called. The commitConnections()
method must still be called by the main thread (synchronously) to control when connections are activated and deactivated.
Synchronous mode is supported by calling monitorConnections()
to accept new connections. This must be followed by a call to commitConnections()
to commit the changes to the owning Server
.
|
pure virtual |
Migrates new connections to the owning Server
and removes expired connections.
For each new connection, the callback set in setConnectionCallback()
is invoked, passing the server, connection and user
argument.
callback | When given, called for each new connection. |
user | User argument passed to callback . |
|
pure virtual |
Returns true if the connection monitor has start.
|
pure virtual |
Called to join the monitor thread.
Returns immediately if not running.
|
pure virtual |
Returns the current running mode.
Asynchronous
mode is set as soon as start(Asynchronous)
is called and drops to None
after calling stop()
once the thread has stopped.
Synchronous
mode is set as soon as start(Synchronous)
is called and drops to None
on calling stop()
.
The mode is None
if not running in either mode.
|
pure virtual |
Accepts new connections and checks for expired connections, but effects neither in the Server
.
This is either called on the main thread for synchronous operation, or internally in asynchronous mode.
|
pure virtual |
Sets the callback invoked for each new connection.
This is invoked from commitConnections()
for each new connection. The arguments passed to the callback are:
server
: the Server
object.connection
: the new Connection
object.user
: the user
argument given here.Write only.
callback | The callback function pointer. |
user | A user pointer passed to the callback whenever it is invoked. |
|
pure virtual |
An overload of setConnectionCallback()
using the C++11 funtion
object.
Both methods are provided to cater for potential ABI issues.
No user argument is supported as the flexibility of std::function
obviates the for such.
callback | The function to invoke for each new connection. |
|
pure virtual |
Starts the monitor listening in the specified mode.
The listening thread is started if mode
is Asynchronous
.
mode | The listening mode. Mode Node is ignored. |
mode
. This includes both newly started and if it was already running in that mode. False is returned if mode
is None
, or differs from the running mode.
|
pure virtual |
Stops listening for further connections.
This requests termination of the monitor thread if running.
Safe to call if not running.
|
pure virtual |
Wait up to timeoutMs
milliseconds for a connection.
Returns immediately if we already have a connection.
timeoutMs | The time out to wait in milliseconds. |