cluster.open support cluster name

This commit is contained in:
Cloud Wu
2014-06-19 16:25:50 +08:00
parent ad9898a209
commit d0468a39f4
4 changed files with 13 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ Dev version
-----------
* Optimize redis driver `compose_message`.
* Add module skynet.harbor for monitor harbor connect/disconnect, see test/testharborlink.lua .
* cluster.open support cluster name.
v0.3.1 (2014-6-16)
-----------

View File

@@ -5,5 +5,5 @@ skynet.start(function()
skynet.newservice("simpledb")
print(skynet.call("SIMPLEDB", "lua", "SET", "a", "foobar"))
print(skynet.call("SIMPLEDB", "lua", "GET", "a"))
cluster.open(2528)
cluster.open "db"
end)

View File

@@ -9,7 +9,11 @@ function cluster.call(node, address, ...)
end
function cluster.open(port)
skynet.call(clusterd, "lua", "listen", "0.0.0.0", port)
if type(port) == "string" then
skynet.call(clusterd, "lua", "listen", port)
else
skynet.call(clusterd, "lua", "listen", "0.0.0.0", port)
end
end
skynet.init(function()

View File

@@ -32,7 +32,12 @@ local node_channel = setmetatable({}, { __index = open_channel })
function command.listen(source, addr, port)
local gate = skynet.newservice("gate")
skynet.call(gate, "lua", "open", { address = addr, port = port })
if port == nil then
local host, port = string.match(node_address[addr], "([^:]+):(.*)$")
skynet.call(gate, "lua", "open", { address = host, port = port })
else
skynet.call(gate, "lua", "open", { address = addr, port = port })
end
skynet.ret(skynet.pack(nil))
end