Giter Club home page Giter Club logo

Comments (11)

calid avatar calid commented on July 22, 2024

can you not use either the non-blocking interface (poll on get_fd) or use has_pollin directly? See the non-blocking and pub/sub examples. I'm not necessarily against implementing a 1:1 zmq_poll binding, but personally I've never needed it and instead use a non-blocking solution. This seems like the modern, idiomatic Perl way to solve this.

from perlzmq.

calid avatar calid commented on July 22, 2024

@garnier-quentin I'm going to close this for now as I feel the non-blocking interface is both sufficient and preferred. But if you (or anyone else) feels strongly about this let me know.

from perlzmq.

garnier-quentin avatar garnier-quentin commented on July 22, 2024

Ok for the non-blocking example. But can we do it with 2..X fd ? I prefer the libzmq bindings. It masks how it works with fd or else.

from perlzmq.

calid avatar calid commented on July 22, 2024

sorry I don't understand, could you provide an example of what you're asking for?

from perlzmq.

garnier-quentin avatar garnier-quentin commented on July 22, 2024

Yes. I would like to do the same:

$polls = [
        {
            socket  => $internal_socket,
            events  => ZMQ_POLLIN,
            callback => \&router_internal_event,
        },
        {
            socket  => $external_socket,
            events  => ZMQ_POLLIN,
            callback => \&router_external_event,
        }
    ];

   while (1) {
      zmq_poll($polls , 5000);
      ....
   }

from perlzmq.

calid avatar calid commented on July 22, 2024

Can you give a compelling reason why that is preferable to:

my $internal_watcher =
    AE::io $internal_socket->get_fd, 0, \&router_internal_event;

my $external_watcher =
    AE::io $external_socket->get_fd, 0, \&router_external_event;

EV::run;

a manual IO poll while loop is quite icky in this day and age...

from perlzmq.

garnier-quentin avatar garnier-quentin commented on July 22, 2024

Because i need to do some treatments. "oldie but goodie" :)

from perlzmq.

calid avatar calid commented on July 22, 2024

treatments?

from perlzmq.

garnier-quentin avatar garnier-quentin commented on July 22, 2024

Not the good word. Sorry. Need to execute some codes. Like: checking death of my childs for example.
You can show the code here: https://github.com/centreon/centreon/blob/master/bin/centreond/centreon/script/centreondcore.pm

from perlzmq.

calid avatar calid commented on July 22, 2024

ok, so instead of doing

sub waiting_ready {
    my (%options) = @_;

    return 1 if (${$options{ready}} == 1);

    my $time = time();
    # We wait 10 seconds
    while (${$options{ready}} == 0 &&
           time() - $time < 10) {
        zmq_poll($centreond->{poll}, 5000);
    }

    if (${$options{ready}} == 0) {
        return 0;
    }

    return 1;
}

do

sub waiting_ready {
    my (%options) = @_;

    return 1 if (${$options{ready}} == 1);

    # We wait 10 seconds
    my $t = AE::timer 10, 0, sub { EV::break };

    my $internal_watcher =
        AE::io $internal_socket->get_fd, 0, \&router_internal_event;

    my $external_watcher =
        AE::io $external_socket->get_fd, 0, \&router_external_event;

    EV::run;

    if (${$options{ready}} == 0) {
        return 0;
    }

    return 1;
}

or somesuch. why is that not possible? Any place you see while (1) { ... zmq_poll ... } can easily be swapped with equivalent anyevent code.

Are you asking for an identical ZMQ::LibZMQ interface just to save you the effort of updating your legacy code? If so, while I sympathize, that's not a valid justification for changing (or in this case adding to) the API. Being backwards compatible with ZMQ::LibZMQ isn't one of the design goals for ZMQ::FFI.

from perlzmq.

garnier-quentin avatar garnier-quentin commented on July 22, 2024

Thanks for the response and the code. I'll try. It should be ok :)

from perlzmq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.