1ZACTOR(3) CZMQ Manual ZACTOR(3)
2
3
4
6 zactor - simple actor framework
7
9 // This is a stable class, and may not change except for emergencies. It
10 // is provided in stable builds.
11 // Actors get a pipe and arguments from caller
12 typedef void (zactor_fn) (
13 zsock_t *pipe, void *args);
14
15 // Create a new actor passing arbitrary arguments reference.
16 CZMQ_EXPORT zactor_t *
17 zactor_new (zactor_fn task, void *args);
18
19 // Destroy an actor.
20 CZMQ_EXPORT void
21 zactor_destroy (zactor_t **self_p);
22
23 // Send a zmsg message to the actor, take ownership of the message
24 // and destroy when it has been sent.
25 CZMQ_EXPORT int
26 zactor_send (zactor_t *self, zmsg_t **msg_p);
27
28 // Receive a zmsg message from the actor. Returns NULL if the actor
29 // was interrupted before the message could be received, or if there
30 // was a timeout on the actor.
31 // Caller owns return value and must destroy it when done.
32 CZMQ_EXPORT zmsg_t *
33 zactor_recv (zactor_t *self);
34
35 // Probe the supplied object, and report if it looks like a zactor_t.
36 CZMQ_EXPORT bool
37 zactor_is (void *self);
38
39 // Probe the supplied reference. If it looks like a zactor_t instance,
40 // return the underlying libzmq actor handle; else if it looks like
41 // a libzmq actor handle, return the supplied value.
42 CZMQ_EXPORT void *
43 zactor_resolve (void *self);
44
45 // Return the actor's zsock handle. Use this when you absolutely need
46 // to work with the zsock instance rather than the actor.
47 CZMQ_EXPORT zsock_t *
48 zactor_sock (zactor_t *self);
49
50 // Self test of this class.
51 CZMQ_EXPORT void
52 zactor_test (bool verbose);
53
54 Please add '@interface' section in './../src/zactor.c'.
55
57 The zactor class provides a simple actor framework. It replaces the
58 CZMQ zthread class, which had a complex API that did not fit the CLASS
59 standard. A CZMQ actor is implemented as a thread plus a PAIR-PAIR
60 pipe. The constructor and destructor are always synchronized, so the
61 caller can be sure all resources are created, and destroyed, when these
62 calls complete. (This solves a major problem with zthread, that a
63 caller could not be sure when a child thread had finished.)
64
65 A zactor_t instance acts like a zsock_t and you can pass it to any CZMQ
66 method that would take a zsock_t argument, including methods in zframe,
67 zmsg, zstr, and zpoller. (zloop somehow escaped and needs catching.)
68
69 An actor function MUST call zsock_signal (pipe) when initialized and
70 MUST listen to pipe and exit on $TERM command.
71
72 Please add @discuss section in ./../src/zactor.c.
73
75 From zactor_test method.
76
77 zactor_t *actor = zactor_new (echo_actor, "Hello, World");
78 assert (actor);
79 zstr_sendx (actor, "ECHO", "This is a string", NULL);
80 char *string = zstr_recv (actor);
81 assert (streq (string, "This is a string"));
82 free (string);
83 zactor_destroy (&actor);
84
85
87 The czmq manual was written by the authors in the AUTHORS file.
88
90 Main web site:
91
92 Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
93
95 Copyright (c) the Contributors as noted in the AUTHORS file. This file
96 is part of CZMQ, the high-level C binding for 0MQ:
97 http://czmq.zeromq.org. This Source Code Form is subject to the terms
98 of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
99 distributed with this file, You can obtain one at
100 http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
101 distribution.
102
104 1. zeromq-dev@lists.zeromq.org
105 mailto:zeromq-dev@lists.zeromq.org
106
107
108
109CZMQ 4.0.2 12/31/2016 ZACTOR(3)