![]() |
![]()
| ![]() |
![]()
NAMEzactor - Class for simple actor framework SYNOPSIS// This is a stable class, and may not change except for emergencies. It // is provided in stable builds. // This class has draft methods, which may change over time. They are not // in stable releases, by default. Use --enable-drafts to enable. // Actors get a pipe and arguments from caller typedef void (zactor_fn) ( DESCRIPTIONThe zactor class provides a simple actor framework. It replaces the CZMQ zthread class, which had a complex API that did not fit the CLASS standard. A CZMQ actor is implemented as a thread plus a PAIR-PAIR pipe. The constructor and destructor are always synchronized, so the caller can be sure all resources are created, and destroyed, when these calls complete. (This solves a major problem with zthread, that a caller could not be sure when a child thread had finished.) A zactor_t instance acts like a zsock_t and you can pass it to any CZMQ method that would take a zsock_t argument, including methods in zframe, zmsg, zstr, and zpoller. (zloop somehow escaped and needs catching.) An actor function MUST call zsock_signal (pipe) when initialized and MUST listen to pipe and exit on $TERM command. Please add @discuss section in ./../src/zactor.c. EXAMPLEFrom zactor_test method. zactor_t *actor = zactor_new (echo_actor, "Hello, World"); assert (actor); zstr_sendx (actor, "ECHO", "This is a string", NULL); char *string = zstr_recv (actor); assert (streq (string, "This is a string")); freen (string); zactor_destroy (&actor); // custom destructor // KTHXBAI_actor ends on "$KTHXBAI" string zactor_t *KTHXBAI = zactor_new (KTHXBAI_actor, NULL); assert (KTHXBAI); // which is the one sent by KTHXBAI_destructor zactor_set_destructor (KTHXBAI, KTHXBAI_destructor); zactor_destroy (&KTHXBAI); // custom destructor // destructor using bsend/brecv zactor_t *BSEND = zactor_new (BSEND_actor, NULL); assert (BSEND); zactor_set_destructor (BSEND, BSEND_destructor); zactor_destroy (&BSEND); #if defined (__WINDOWS__) zsys_shutdown(); #endif AUTHORSThe czmq manual was written by the authors in the AUTHORS file. RESOURCESMain web site: Report bugs to the email <zeromq-dev@lists.zeromq.org[1]> COPYRIGHTCopyright (c) the Contributors as noted in the AUTHORS file. This file is part of CZMQ, the high-level C binding for 0MQ: http://czmq.zeromq.org. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. LICENSE included with the czmq distribution. NOTES
mailto:zeromq-dev@lists.zeromq.org
|