zmqpp
4.1.2
C++ bindings for 0mq (libzmq)
|
An actor is a thread with a pair socket connected to its parent. More...
#include <actor.hpp>
Public Types | |
typedef std::function< bool(socket *pipe) > | ActorStartRoutine |
The user defined function type. More... | |
Public Member Functions | |
actor (ActorStartRoutine routine) | |
Create a new actor. More... | |
actor (const actor &)=delete | |
actor (actor &&o) | |
Move constructor. More... | |
actor & | operator= (actor &&o) |
Move-assignment operator. More... | |
virtual | ~actor () |
socket * | pipe () |
const socket * | pipe () const |
bool | stop (bool block=false) |
Sends signal::stop to the actor thread. More... | |
Private Member Functions | |
void | start_routine (socket *child, ActorStartRoutine routine) |
Call a user defined function and performs cleanup once it returns. More... | |
std::string | bind_parent () |
Bind the parent socket and return the endpoint used. More... | |
Private Attributes | |
socket * | parent_pipe_ |
The parent thread socket. More... | |
socket * | child_pipe_ |
The child end of the pipe. More... | |
bool | stopped_ |
Keeps track of the status of the actor thread. More... | |
bool | retval_ |
Static Private Attributes | |
static context | actor_pipe_ctx_ |
This static, per process zmqpp::context, is used to connect PAIR socket between Actor and their parent thread. More... | |
An actor is a thread with a pair socket connected to its parent.
It aims to be similar to CMZQ's zactor.
From the parent thread, instancing an actor will spawn a new thread, and install a pipe between those two threads.
You don't have to manage the 2 PAIR sockets. The parent's one will be destroyed when the actor dies, and the child's end is taken care of when the user routine ends.
typedef std::function<bool (socket *pipe) > zmqpp::actor::ActorStartRoutine |
The user defined function type.
zmqpp::actor::actor | ( | ActorStartRoutine | routine | ) |
Create a new actor.
This will effectively create a new thread and runs the user supplied routine. The constructor expect a signal from the routine before returning.
Expect to receive either signal::ko or signal::ok before returning. If it receives signal::ko, it will throw.
routine | to be executed. |
|
delete |
zmqpp::actor::actor | ( | actor && | o | ) |
|
virtual |
|
private |
Bind the parent socket and return the endpoint used.
Since endpoint are generated and have to be tested for availability this method is reponsible for finding a valid endpoint to bind to.
socket * zmqpp::actor::pipe | ( | ) |
const socket * zmqpp::actor::pipe | ( | ) | const |
|
private |
Call a user defined function and performs cleanup once it returns.
We use a copy of child_pipe_ here; this is to avoid a race condition where the destructor would be called before start_routine finishes but after it sent signal::ok / signal::ko. The actor object would be invalid (because already destroyed).
child | a copy of child_pipe_. |
routine | user routine that will be called |
bool zmqpp::actor::stop | ( | bool | block = false | ) |
Sends signal::stop to the actor thread.
The actor thread shall stop as soon as possible. The return value is only relevant when block is true. If block is false (the default), this method will return true.
It is safe to call stop() multiple time (to ask the actor to shutdown, and then a bit later call stop(true) to make sure it is really stopped)
block | whether or not we wait until the actor thread stops. |
|
staticprivate |
This static, per process zmqpp::context, is used to connect PAIR socket between Actor and their parent thread.
|
private |
The child end of the pipe.
It is closed and freed when the routine ran by the actor ends.
|
private |
The parent thread socket.
This socket will be closed and freed by the actor destructor.
|
private |
|
private |
Keeps track of the status of the actor thread.