Skip to content

Instantly share code, notes, and snippets.

@agladysh
Created April 23, 2011 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agladysh/938429 to your computer and use it in GitHub Desktop.
Save agladysh/938429 to your computer and use it in GitHub Desktop.
lua-zmq inverted pub-sub problem
# Spawn receiver 1
$ lua receiver.lua &
[1] 9728
R 9728 init
R 9728 create socket
R 9728 bind socket
R 9728 subscribe
R 9728 before receive msg loop
# Spawn receiver 2
$ lua receiver.lua &
[2] 9735
R 9735 init
R 9735 create socket
R 9735 bind socket
R 9735 subscribe
R 9735 before receive msg loop
# Spawn receiver 3
$ lua receiver.lua &
[3] 9739
R 9739 init
R 9739 create socket
R 9739 bind socket
R 9739 subscribe
R 9739 before receive msg loop
# Spawn sender
$ lua sender.lua
S 9755 init
S 9755 create socket
S 9755 connect socket
S 9755 sending MSG 1
S 9755 sending MSG 2
S 9755 sending MSG 3
S 9755 close
S 9755 term
R 9739 recieved MSG 1 nil
R 9739 recieved MSG 2 nil
R 9739 recieved MSG 3 nil
R 9739 close
R 9739 term
S 9755 done
R 9739 done
[3]+ Done lua receiver.lua
# Spawn sender again
$ lua sender.lua
S 9759 init
S 9759 create socket
S 9759 connect socket
S 9759 sending MSG 1
S 9759 sending MSG 2
S 9759 sending MSG 3
S 9759 close
S 9759 term
# Sender hangs
local posix = require 'posix'
local zmq = require 'zmq'
local old_print = print
local print = function(...)
print("R", posix.getpid("pid"), ...)
end
print("init")
local context = assert(zmq.init(1))
print("create socket")
local conn = assert(context:socket(zmq.SUB))
print("bind socket")
assert(conn:bind("ipc://tmp.ipc"))
print("subscribe")
assert(conn:setopt(zmq.SUBSCRIBE, ""))
print("before receive msg loop")
for i = 1, 3 do
print("recieved", conn:recv())
end
print("close")
conn:close()
conn = nil
print("term")
context:term()
context = nil
print("done")
local posix = require 'posix'
local zmq = require 'zmq'
local old_print = print
local print = function(...)
print("S", posix.getpid("pid"), ...)
end
print("init")
local context = assert(zmq.init(1))
print("create socket")
local conn = assert(context:socket(zmq.PUB))
print("connect socket")
assert(conn:connect("ipc://tmp.ipc"))
for i = 1, 3 do
local msg = "MSG " .. i
print("sending", msg)
assert(conn:send(msg))
end
print("close")
conn:close()
conn = nil
print("term")
context:term()
context = nil
print("done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment