poll

Input/output multiplexing.

The timeout parameter may have the special value infiniteDuration which means no _timeout. This is translated to an argument value of -1 in the C API.

  1. uint poll(zmq_pollitem_t[] items, Duration timeout)
  2. uint poll(PollItem[] items, Duration timeout)
    @safe @trusted
    uint
    poll

Return Value

Type: uint

The number of PollItem structures with events signalled in PollItem.returnedEvents, or 0 if no events have been signalled.

Throws

ZmqException if $(ZMQ) reports an error.

Corresponds to

$(ZMQREF zmq_poll())

Examples

auto socket1 = zmqd.Socket(zmqd.SocketType.pull);
socket1.bind("inproc://zmqd_poll_example");

import std.socket;
auto socket2 = new std.socket.Socket(
    AddressFamily.INET,
    std.socket.SocketType.DGRAM);
socket2.bind(new InternetAddress(InternetAddress.ADDR_ANY, 5678));

auto socket3 = zmqd.Socket(zmqd.SocketType.push);
socket3.connect("inproc://zmqd_poll_example");
socket3.send("test");

import core.thread: Thread;
Thread.sleep(10.msecs);

auto items = [
    PollItem(socket1, PollFlags.pollIn),
    PollItem(socket2, PollFlags.pollIn | PollFlags.pollOut),
    PollItem(socket3, PollFlags.pollIn),
];

const n = poll(items, 100.msecs);
assert (n == 2);
assert (items[0].returnedEvents == PollFlags.pollIn);
assert (items[1].returnedEvents == PollFlags.pollOut);
assert (items[2].returnedEvents == 0);
socket2.close();

Meta