ZMQ Socket poller.
-
poller:add (socket, events, callback)
-
Add a ZMQ Socket or fd to the poller.
You can add one socket multiple times.
Parameters:
- socket
(lzmq.socket, number or Pollable)
ZMQ socket or fd
- events
number
zmq poll events bitmask
- callback
callable
called when event is raised
Usage:
poller:add(sock, zmq.POLLIN, function(sock) print(sock, " is readable.") end)
poller:add(sock, zmq.POLLOUT, function(sock) print(sock, " is writable.") end)
poller:add(sock, zmq.POLLIN+zmq.POLLOUT, function(sock, revents)
print(sock, " has events:", revents)
end)
-
poller:modify (socket, events, callback)
-
Change the events or callback for a socket/fd.
Note. You can modify only `last` socket.
Parameters:
- socket
(lzmq.socket, number or Pollable)
ZMQ socket or fd
- events
number
zmq poll events bitmask
if this parameter is 0 then socket will be removed.
- callback
callable
called when event is raised
if this parameter is absent then socket will be removed.
Usage:
poller:add(sock, zmq.POLLIN, function(sock) print(sock, " is readable.") end)
poller:modify(sock, zmq.POLLOUT, function(sock) print(sock, " is writable.") end)
-
poller:remove (socket)
-
Remove a socket/fd from the poller.
Note. You can remove only `last` socket.
Parameters:
Usage:
poller:add(sock, zmq.POLLIN, function(sock) print(sock, " is readable.") end)
poller:add(sock, zmq.POLLOUT, function(sock) print(sock, " is writable.") end)
poller:remove(sock)
poller:remove(sock)
-
poller:poll ([timeout=-1])
-
Wait for events on the registered sockets.
Parameters:
- timeout
number
msec to wait events. -1 - wait indefinitely.
(default -1)
Returns:
number
of events that has been dispatched.
Or
-
nil
-
lzmq.error
error object
-
poller:start ()
-
Start an event loop waiting for and dispatching events.
-
poller:stop ()
-
Stop the event loop.