[zeromq-dev] Perl: zmq_poll

Pedro Melo melo at simplicidade.org
Fri Dec 28 17:43:14 CET 2012


Hi,

On Fri, Dec 28, 2012 at 3:49 PM, Nishant Mittal <nmittal at rblt.com> wrote:
> I checked the example code for multiple socket poller
> (http://zguide.zeromq.org/pl:mspoller) but its not clear to me as to how I
> can get a handle to the socket that fired the callback function. The example
> just prints a warning message and does not attempt to get the message.

A tweak to the example:

    zmq_poll([
        {
            socket  => $receiver,
            events  => ZMQ_POLLIN,
            callback => sub {
                warn "Process task";
                ## Read messages from $receiver socket now
            }
        }, {
            socket  => $subscriber,
            events  => ZMQ_POLLIN,
            callback => sub {
                warn "Process weather update";
                ## Read messages from $subscriber socket now
            }
        },
    ]);

Basically both $receiver and $subscriber are in scope of the sub {}
callback, so you just use them directly.

Bye,
-- 
Pedro Melo
@pedromelo
http://www.simplicidade.org/
http://about.me/melo
xmpp:melo at simplicidade.org
mailto:melo at simplicidade.org



More information about the zeromq-dev mailing list