From e47a4921faaecbb1e2710e48bcb36c64221ad6a8 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Fri, 27 Nov 2015 18:13:50 +0800 Subject: [PATCH] bugfix. remote publish first, see issue #391 --- service/multicastd.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/service/multicastd.lua b/service/multicastd.lua index 2ff1a7f0..3010e2c9 100644 --- a/service/multicastd.lua +++ b/service/multicastd.lua @@ -66,6 +66,16 @@ end -- publish a message, for local node, use the message pointer (call mc.bind to add the reference) -- for remote node, call remote_publish. (call mc.unpack and skynet.tostring to convert message pointer to string) local function publish(c , source, pack, size) + local remote = channel_remote[c] + if remote then + -- remote publish should unpack the pack, because we should not publish the pointer out. + local _, msg, sz = mc.unpack(pack, size) + local msg = skynet.tostring(msg,sz) + for node in pairs(remote) do + remote_publish(node, c, source, msg) + end + end + local group = channel[c] if group == nil or next(group) == nil then -- dead channel, delete the pack. mc.bind returns the pointer in pack @@ -79,15 +89,6 @@ local function publish(c , source, pack, size) -- the msg is a pointer to the real message, publish pointer in local is ok. skynet.redirect(k, source, "multicast", c , msg) end - local remote = channel_remote[c] - if remote then - -- remote publish should unpack the pack, because we should not publish the pointer out. - local _, msg, sz = mc.unpack(pack, size) - local msg = skynet.tostring(msg,sz) - for node in pairs(remote) do - remote_publish(node, c, source, msg) - end - end end skynet.register_protocol {