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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to