ZACTOR(3)
π ZACTOR(3) β straight outta the CZMQ Manual π
hiii bestie π«Ά welcome to zactor, aka the class that gives you a simple actor framework and honestly? she's the moment. this page lives in the CZMQ manual, section 3, and it's all about making a thread plus a pipe feel like a whole vibe instead of a whole headache. no cap.
β¨ NAME β¨
zactor β the class for a simple actor framework. that's it, that's the girl. π
β¨ SYNOPSIS β¨
okay so first things first, read the receipts exactly as they are, because this is the actual source energy:
// 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) (
zsock_t *pipe, void *args);
// Create a new actor passing arbitrary arguments reference.
CZMQ_EXPORT zactor_t *
zactor_new (zactor_fn task, void *args);
// Destroy an actor.
CZMQ_EXPORT void
zactor_destroy (zactor_t **self_p);
// Send a zmsg message to the actor, take ownership of the message
// and destroy when it has been sent.
CZMQ_EXPORT int
zactor_send (zactor_t *self, zmsg_t **msg_p);
// Receive a zmsg message from the actor. Returns NULL if the actor
// was interrupted before the message could be received, or if there
// was a timeout on the actor.
// Caller owns return value and must destroy it when done.
CZMQ_EXPORT zmsg_t *
zactor_recv (zactor_t *self);
// Probe the supplied object, and report if it looks like a zactor_t.
CZMQ_EXPORT bool
zactor_is (void *self);
// Probe the supplied reference. If it looks like a zactor_t instance,
// return the underlying libzmq actor handle; else if it looks like
// a libzmq actor handle, return the supplied value.
CZMQ_EXPORT void *
zactor_resolve (void *self);
// Return the actor's zsock handle. Use this when you absolutely need
// to work with the zsock instance rather than the actor.
CZMQ_EXPORT zsock_t *
zactor_sock (zactor_t *self);
// Self test of this class.
CZMQ_EXPORT void
zactor_test (bool verbose);
#ifdef CZMQ_BUILD_DRAFT_API
// Function to be called on zactor_destroy. Default behavior is to send zmsg_t with string "$TERM" in a first frame.
//
// An example - to send $KTHXBAI string
//
// if (zstr_send (self, "$KTHXBAI") == 0)
// zsock_wait (self);
typedef void (zactor_destructor_fn) (
zactor_t *self);
// *** Draft method, for development use, may change without warning ***
// Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
CZMQ_EXPORT void
zactor_set_destructor (zactor_t *self, zactor_destructor_fn destructor);
#endif // CZMQ_BUILD_DRAFT_API
Please add '@interface' section in './../src/zactor.c'.
heads up bestie: this is a stable class, so she doesn't change unless it's an actual emergency, and she ships in stable builds. β¨ but she ALSO has draft methods which can change over time and are not in stable releases by default β you flip those on with --enable-drafts.
πΈ the function lineup, explained with love
zactor_fnβ the actor's signature. the actor gets a pipe and the args from whoever called it:zsock_t *pipe, void *args.zactor_new (zactor_fn task, void *args)β makes a brand new actor and passes along an arbitrary args reference. returns azactor_t *.zactor_destroy (zactor_t **self_p)β bye bye actor, takes the pointer-to-pointer like a good CZMQ citizen.zactor_send (zactor_t *self, zmsg_t **msg_p)β sends azmsgmessage to the actor, and she takes ownership of that message and destroys it once it's been sent. returnsint.zactor_recv (zactor_t *self)β grabs azmsgmessage back from the actor. returnsNULLif the actor got interrupted before the message could arrive, or if there was a timeout on the actor. the caller owns the return value and must destroy it when done π«Άzactor_is (void *self)β probes the object you hand her and tells you (with abool) whether it looks like azactor_t.zactor_resolve (void *self)β probes the reference. if it looks like azactor_tinstance you get back the underlying libzmq actor handle; if it looks like a libzmq actor handle instead, you just get back the value you supplied. returnsvoid *.zactor_sock (zactor_t *self)β hands you the actor'szsockhandle. use this when you absolutely need to work with thezsockinstance rather than the actor itself.zactor_test (bool verbose)β the self test of this class. go off, king. π
π the draft girlies (only with CZMQ_BUILD_DRAFT_API)
zactor_destructor_fnβ the function that gets called onzactor_destroy. default behavior is to send azmsg_twith the string"$TERM"in a first frame. the source shows an example of sending a$KTHXBAIstring:
if (zstr_send (self, "$KTHXBAI") == 0)
zsock_wait (self);
zactor_set_destructor (zactor_t *self, zactor_destructor_fn destructor)β * draft method, for development use, may change without warning * swaps the default destructor for a custom function. and listen: the actor MUST be able to handle the new message instead of the default$TERM. no cap, if your actor can't cope, that's on you bestie π
β¨ DESCRIPTION β¨
so what even IS she? zactor gives you a simple actor framework. she replaces the CZMQ zthread class, which had a complex API that did not fit the CLASS standard. so zthread is giving "it's complicated" and zactor is giving "we're just vibing". π
a CZMQ actor is implemented as a thread plus a PAIR-PAIR pipe. and 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, where a caller could not be sure when a child thread had finished. lowkey iconic problem-solving behavior. π
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. π can't relate, can't stop her.)
and here's the rule that is NOT optional:
an actor function MUST callzsock_signal (pipe)when initialized, and MUST listen topipeand exit on the$TERMcommand. periodt. π
also, the source has a lil note: Please add @discuss section in ./../src/zactor.c.
β¨ EXAMPLE β¨
straight from the zactor_test method, no edits, no filter:
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
see how she did the custom destructor TWICE? once with the $KTHXBAI string and once with bsend/brecv? obsessed. π₯
β¨ AUTHORS β¨
the czmq manual was written by the authors in the AUTHORS file. credit where credit is due, always. π«Ά
β¨ RESOURCES β¨
main web site:
report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
β¨ COPYRIGHT β¨
Copyright (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 β¨
zeromq-dev@lists.zeromq.orgmailto:zeromq-dev@lists.zeromq.org
and that's the whole page bestie, every flag, every function, every warning, all of it kept intact because we don't skip the "boring" parts in this house π
sign-off: this was CZMQ 4.2.1, dated 01/16/2026, and you just read ZACTOR(3). go build something cute with a pipe. mwah. πβ¨π¦
π¦ where this page comes from
- fedora 44: czmq-devel 4.2.1-24.fc44 Β· MPL-2.0
- fedora 44: czmq-devel 4.2.1-24.fc44 Β· MPL-2.0
- ubuntu resolute: libczmq-dev 4.2.1-3build1 Β· MPL-2.0
- ubuntu stonking: libczmq-dev 4.2.1-3build1 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms