diff --git a/lualib-src/lua-multicast.c b/lualib-src/lua-multicast.c index 866821d4..609169d4 100644 --- a/lualib-src/lua-multicast.c +++ b/lualib-src/lua-multicast.c @@ -83,7 +83,7 @@ mc_unpacklocal(lua_State *L) { if (sz != sizeof(*pack)) { return luaL_error(L, "Invalid multicast package size %d", sz); } - lua_settop(L, 1); + lua_pushlightuserdata(L, *pack); lua_pushlightuserdata(L, (*pack)->data); lua_pushunsigned(L, (*pack)->size); return 3; @@ -92,6 +92,8 @@ mc_unpacklocal(lua_State *L) { /* lightuserdata struct mc_package ** integer reference + + return mc_package * */ static int mc_bindrefer(lua_State *L) { @@ -102,16 +104,17 @@ mc_bindrefer(lua_State *L) { } (*pack)->reference = ref; - return 0; + lua_pushlightuserdata(L, *pack); + + return 1; } /* - lightuserdata struct mc_package ** + lightuserdata struct mc_package * */ static int mc_closelocal(lua_State *L) { - struct mc_package **ptr = lua_touserdata(L,1); - struct mc_package *pack = *ptr; + struct mc_package *pack = lua_touserdata(L,1); int ref = __sync_sub_and_fetch(&pack->reference, 1); if (ref <= 0) { diff --git a/service/multicastd.lua b/service/multicastd.lua index 5a7f9d2a..7bafab78 100644 --- a/service/multicastd.lua +++ b/service/multicastd.lua @@ -68,18 +68,20 @@ end local function publish(c , source, pack, size) local group = channel[c] if group == nil then - -- dead channel, delete the pack - mc.bind(pack, 1) + -- dead channel, delete the pack. mc.bind returns the pointer in pack + local pack = mc.bind(pack, 1) mc.close(pack) return end mc.bind(pack, channel_n[c]) local msg = skynet.tostring(pack, size) for k in pairs(group) do + -- 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