From d0468a39f4bb33eafea2e0972b9c8dad34793fde Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Thu, 19 Jun 2014 16:25:50 +0800 Subject: [PATCH] cluster.open support cluster name --- HISTORY.md | 1 + examples/cluster1.lua | 2 +- lualib/cluster.lua | 6 +++++- service/clusterd.lua | 7 ++++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index addc8955..e4b2b7f7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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) ----------- diff --git a/examples/cluster1.lua b/examples/cluster1.lua index 73fad761..551b0f38 100644 --- a/examples/cluster1.lua +++ b/examples/cluster1.lua @@ -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) diff --git a/lualib/cluster.lua b/lualib/cluster.lua index e4f6cfa2..bc4312b3 100644 --- a/lualib/cluster.lua +++ b/lualib/cluster.lua @@ -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() diff --git a/service/clusterd.lua b/service/clusterd.lua index ef6bff68..51494971 100644 --- a/service/clusterd.lua +++ b/service/clusterd.lua @@ -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