[zeromq-dev] Polling API

gonzalo diethelm gdiethelm at dcv.cl
Fri Apr 9 17:43:09 CEST 2010


> Well, I would say that polling is ripe to get some standardised
> interface. Something like epoll/kqueue.
> 
> There's one provided by Python binding, now there's Java, Lisp copies
> the C interface, not sure about PHP and other languages...
> 
> Thoughts anyone?

To get this discussion going, here is an example of how things work in
Java now:

  // create a 0MQ context that has poll enabled
  ZMQ.Context ctx = ZMQ.context(1, 1, ZMQ.POLL);

  // create two sockets
  ZMQ.Socket spip = ctx.socket(ZMQ.REQ);
  ZMQ.Socket smsg = ctx.socket(ZMQ.PUB);

  // create a poller for two sockets
  ZMQ.Poller poller = ctx.poller(2);

  // configure poller to wait forever
  poller.setTimeout(-1);

  // will poll for INPUT on socket spip.
  // ip is the index for sockete spip in the poll set.
  int ip = poller.register(spip, ZMQ.POLLIN);

  // will poll for OUTPUT on socket smsg
  // im is the index for sockete smsg in the poll set.
  int im = poller.register(smsg, ZMQ.POLLOUT);

  // loop forever; this loop should have a termination clause!
  while (true) {
      // call poll, possibly block
      long p = poller.poll();

       // poll may have spurious returns
      if (p <= 0)
          continue;

      // Can we write on smsg? Go ahead.
      if (poller.pollout(im))
          process_messages();

      // Can we read on spip? Go ahead.
      if (poller.pollin(ip))
          process_pipe();
  }

-- 
Gonzalo Diethelm



----------------------------------------- 
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena. 
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje. 

"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law. 
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message. 




More information about the zeromq-dev mailing list