mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
close uncomplete when socket disconnect, see Issue #280
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user