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

@@ -4,6 +4,7 @@ local socket = require "socket"
local sproto = require "sproto"
local sprotoloader = require "sprotoloader"
local WATCHDOG
local host
local send_request
@@ -26,6 +27,10 @@ function REQUEST:handshake()
return { msg = "Welcome to skynet, I will send heartbeat every 5 sec." }
end
function REQUEST:quit()
skynet.call(WATCHDOG, "lua", "close", client_fd)
end
local function request(name, args, response)
local f = assert(REQUEST[name])
local r = f(args)
@@ -62,7 +67,10 @@ skynet.register_protocol {
end
}
function CMD.start(gate, fd)
function CMD.start(conf)
local fd = conf.client
local gate = conf.gate
WATCHDOG = conf.watchdog
-- slot 1,2 set at main.lua
host = sprotoloader.load(1):host "package"
send_request = host:attach(sprotoloader.load(2))
@@ -77,6 +85,11 @@ function CMD.start(gate, fd)
skynet.call(gate, "lua", "forward", fd)
end
function CMD.disconnect()
-- todo: do something before exit
skynet.exit()
end
skynet.start(function()
skynet.dispatch("lua", function(_,_, command, ...)
local f = CMD[command]