[zeromq-dev] Using polling with zactor in C

Robert Johnston robert at layer2.com
Mon Dec 14 22:52:27 CET 2015


Hi Pieter,

That got it!  Another Ah Ha! Moment.  I haven’t had the big one yet, only a plethora of small ones.  So I am taking the gradual path to enlightenment.

Next up: coordinating two nodes of the application as equal partners on the network.  Last time I did it with DEALER/DEALER pairs for a command channel and DEALER/ROUTER pairs for a data channel.  Needlessly complex, and awkward - especially when I had to add authentication/encryption.

Since then I have seen you recommend the harmony pattern for this situation, so I will try that this time.

Thanks for giving us a real solution to our real problems.

Robert

-----Original Message-----
From: pieterh at gmail.com [mailto:pieterh at gmail.com] On Behalf Of Pieter Hintjens
Sent: Saturday, December 12, 2015 11:37 PM
To: robert at layer2.com; ZeroMQ development list <zeromq-dev at lists.zeromq.org>
Subject: Re: [zeromq-dev] Using polling with zactor in C

Hi Robert,

You are mixing abstractions here. The zmq_poll layer takes zmq sockets, which are void pointers. The CZMQ zsock_t class is a higher-level socket object. If you look at the CZMQ examples you'll see we use zloop or zpoller (simpler, and recommended) to work on zsock_t objects.

-Pieter

On Sat, Dec 12, 2015 at 9:28 PM, Robert Johnston <robert at layer2.com> wrote:
> Hi,
>
>
>
> I had an application using 0mq V3.x that used zthread_fork to create 
> workers with sockets to the outside world. The threads used zmq_poll 
> to catch events from the main application and the sockets.
>
>
>
> Now I have updated to V4.2.0 and trying to re-do the application the 
> zactor way. And not having much luck with polling.
>
>
>
> As a simple test, I used the echo test with polling added to 
> echo_actor (partially shown below). Nothing happens.  If I comment out 
> the “if (items[0] …” line, the test runs.
>
>
>
> What am I missing? Does zactor require a different polling method? Can 
> you point me to an example?
>
>
>
> Any and all comments, suggestions, praise, or blame gratefully accepted.
>
>
>
> Thanks
>
>
>
> Robert
>
>
>
> //
> ----------------------------------------------------------------------
> ----
>
> //  Actor
>
> //  must call zsock_signal (pipe) when initialized
>
> //  must listen to pipe and exit on $TERM command
>
>
>
> void
>
> echo_actor (zsock_t *pipe, void *args)
>
> {
>
>    zmq_pollitem_t items[] =
>
>    {
>
>       {pipe, 0, ZMQ_POLLIN, 0}
>
>    };
>
>
>
>    //  Do some initialization
>
>    assert (streq ((char *) args, "Hello, World"));
>
>    zsock_signal (pipe, 0);
>
>
>
>    bool terminated = false;
>
>    while (!terminated) {
>
>       zmq_poll (items, 1, 0);
>
>
>
>       if (items[0].revents & ZMQ_POLLIN)
>
>       {
>
>            Etc.
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>




More information about the zeromq-dev mailing list