close uncomplete when socket disconnect, see Issue #280

This commit is contained in:
Cloud Wu
2015-05-29 21:11:02 +08:00
parent 07dbfd8651
commit 24f6994b50
5 changed files with 44 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
local skynet = require "skynet"
local netpack = require "netpack"
require "skynet.manager"
local CMD = {}
local SOCKET = {}
@@ -10,15 +9,16 @@ local agent = {}
function SOCKET.open(fd, addr)
skynet.error("New client from : " .. addr)
agent[fd] = skynet.newservice("agent")
skynet.call(agent[fd], "lua", "start", gate, fd)
skynet.call(agent[fd], "lua", "start", { gate = gate, client = fd, watchdog = skynet.self() })
end
local function close_agent(fd)
local a = agent[fd]
agent[fd] = nil
if a then
-- The better way is send a message to agent, and let agent exit self.
skynet.kill(a)
agent[fd] = nil
skynet.call(gate, "lua", "kick", fd)
-- disconnect never return
skynet.send(a, "lua", "disconnect")
end
end
@@ -39,6 +39,10 @@ function CMD.start(conf)
skynet.call(gate, "lua", "open" , conf)
end
function CMD.close(fd)
close_agent(fd)
end
skynet.start(function()
skynet.dispatch("lua", function(session, source, cmd, subcmd, ...)
if cmd == "socket" then