[zeromq-dev] czmq examples / reactor shut down
Luca Boccassi
luca.boccassi at gmail.com
Fri Feb 16 19:44:34 CET 2018
On Fri, 2018-02-16 at 18:13 +0000, Georger, Joseph wrote:
> Hey all,
>
> Big ZMQ fan, love the guide. Lately I’ve been trying to step up to
> CZMQ for a project. I was wondering if there were any plans to update
> the CZMQ examples there with ones conforming to the latest API? I
> always found the examples helpful. All I see in CZMQ are code
> snippets, I would love to see a fully worked out reactor / zloop
> example using zactor handlers. I’m confused as to how to shut it
> down properly / how the actors handle $TERM….
>
> Thanks,
> Joe
It should definitely be done - but there aren't plans as such,
contributions are welcome.
To use zloop + zactor you can to do something like:
int zactor_term(zloop_t *loop, zsock_t *s, void *arg)
{
int interrupt = 0;
char *msg = zstr_recv (s);
if (zsys_interrupted || (msg && !strcmp(msg, "$TERM")))
interrupt = -1;
free(msg);
return interrupt;
}
void actor (zsock_t *pipe, void *args)
{
zloop_t *loop = zloop_new ();
assert (loop);
zloop_reader(loop, pipe, zactor_term, NULL);
// zloop_reader (...) // as many other readers as you need
zsock_signal (pipe, 0);
while (!zsys_interrupted) {
if (zloop_start (loop) != 0)
break; // termination received
}
// zsock_destroy (...) // if any
zloop_destroy (&loop);
}
--
Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180216/f0625489/attachment.sig>
More information about the zeromq-dev
mailing list