diff --git a/service/gate.lua b/service/gate.lua index 5d81ef4b..ef4c24af 100644 --- a/service/gate.lua +++ b/service/gate.lua @@ -1,6 +1,5 @@ local skynet = require "skynet" local gateserver = require "snax.gateserver" -local netpack = require "skynet.netpack" local watchdog local connection = {} -- fd -> connection : { fd , client, agent , ip, mode } @@ -22,9 +21,12 @@ function handler.message(fd, msg, sz) local c = connection[fd] local agent = c.agent if agent then + -- It's safe to redirect msg directly , gateserver framework will not free msg. skynet.redirect(agent, c.client, "client", fd, msg, sz) else - skynet.send(watchdog, "lua", "socket", "data", fd, netpack.tostring(msg, sz)) + skynet.send(watchdog, "lua", "socket", "data", fd, skynet.tostring(msg, sz)) + -- skynet.tostring will copy msg to a string, so we must free msg here. + skynet.trash(msg,sz) end end