support multi protocol

This commit is contained in:
云风
2012-08-31 21:18:19 +08:00
parent 1ee802c5c5
commit 0a886cd57c
47 changed files with 542 additions and 520 deletions

View File

@@ -3,28 +3,26 @@ local string = string
local instance = {}
local function _extract( service, ...)
return service , table.concat({...}, " ")
end
skynet.register(".launcher")
skynet.dispatch(function(msg, sz , session, address)
if session == 0 then
-- init notice
local reply = instance[address]
if reply then
skynet.send(reply[2] , reply[1], skynet.pack(address))
instance[address] = nil
end
else
-- launch request
local service , param = _extract(skynet.unpack(msg,sz))
local inst = skynet.launch(service, param)
if inst then
instance[inst] = { session, address }
skynet.start(function()
skynet.dispatch("lua" , function(session, address , service, ...)
if service == nil then
-- init notice
local reply = instance[address]
if reply then
skynet.redirect(reply.address , 0, "response", reply.session, skynet.pack(address))
instance[address] = nil
end
else
skynet.send(address, session, skynet.pack(nil))
-- launch request
local param = table.concat({...}, " ")
local inst = skynet.launch(service, param)
if inst then
instance[inst] = { session = session, address = address }
else
skynet.ret(skynet.pack(nil))
end
end
end
end)
end)
skynet.register(".launcher")