Skip to content

Instantly share code, notes, and snippets.

@moteus moteus/output.txt
Last active Jul 14, 2016

What would you like to do?
Test zmq poll with inproc transport using libuv
ZMQ Version: 4 2 0
Timer recv: hello #1
Timer recv: hello #2
Timer recv: hello #3
Timer recv: hello #4
No messages ([ZMQ][EAGAIN] Resource temporarily unavailable (11))
Poll recv: hello #5
Poll recv: hello #6
Poll recv: hello #7
Poll recv: hello #8
Poll recv: hello #9
local uv = require "lluv"
local zmq = require "lzmq"
print("ZMQ Version:", zmq.version(true))
-- Try set timeout e.g. to 5000
local MAGIC_TIMEOUT = 5000
local ep = "inproc://hello"
local ctx = zmq.context()
local srv = ctx:socket{"PUB", bind = ep }
local cli = ctx:socket{"SUB", connect = ep, subscribe = "" }
local counter = 1
uv.timer():start(1000, 1000, function()
srv:send("hello #" .. counter)
counter = counter + 1
-- `Magic` timer. After it fire all statrs work.
uv.timer():start(MAGIC_TIMEOUT, function()
-- this is enouth
if not cli:has_event(zmq.POLLIN) then
return print("Timer no messages")
-- but if we have messages we have read all of them
while true do
local msg, err = cli:recvx(zmq.DONTWAIT)
if not msg then return print("No messages (" .. tostring(err) .. ")" ) end
print("Timer recv:", msg)
uv.poll_socket(cli:fd()):start(function(handle, err, event)
if err then
print("Poll error: ", err)
return uv.stop()
while cli:has_event(zmq.POLLIN) do
local msg, err = cli:recvx()
if not msg then
print("Recv error : ", err)
print("Poll recv:", msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.