mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
skynet filter
This commit is contained in:
@@ -174,6 +174,12 @@ function skynet.call(addr, typename, ...)
|
|||||||
return p.unpack(coroutine.yield("CALL", session))
|
return p.unpack(coroutine.yield("CALL", session))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function skynet.rawcall(addr, typename, msg, sz)
|
||||||
|
local p = proto[typename]
|
||||||
|
local session = c.send(addr, p.id , nil , msg, sz)
|
||||||
|
return coroutine.yield("CALL", session)
|
||||||
|
end
|
||||||
|
|
||||||
function skynet.ret(msg, sz)
|
function skynet.ret(msg, sz)
|
||||||
msg = msg or ""
|
msg = msg or ""
|
||||||
coroutine.yield("RETURN", msg, sz)
|
coroutine.yield("RETURN", msg, sz)
|
||||||
@@ -203,32 +209,40 @@ function skynet.dispatch_unknown_response(unknown)
|
|||||||
return prev
|
return prev
|
||||||
end
|
end
|
||||||
|
|
||||||
local function start_skynet()
|
local function dispatch_message(prototype, msg, sz, session, source, ...)
|
||||||
c.callback(function(prototype, msg, sz, session, source)
|
-- PTYPE_RESPONSE = 1, read skynet.h
|
||||||
-- PTYPE_RESPONSE = 1, read skynet.h
|
if prototype == 1 then
|
||||||
if prototype == 1 then
|
local co = session_id_coroutine[session]
|
||||||
local co = session_id_coroutine[session]
|
if co == "BREAK" then
|
||||||
if co == "BREAK" then
|
session_id_coroutine[session] = nil
|
||||||
session_id_coroutine[session] = nil
|
elseif co == nil then
|
||||||
elseif co == nil then
|
unknown_response(session, source, msg, sz)
|
||||||
unknown_response(session, source, msg, sz)
|
|
||||||
else
|
|
||||||
session_id_coroutine[session] = nil
|
|
||||||
suspend(co, coroutine.resume(co, msg, sz))
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local p = assert(proto[prototype], prototype)
|
session_id_coroutine[session] = nil
|
||||||
local f = p.dispatch
|
suspend(co, coroutine.resume(co, msg, sz))
|
||||||
if f then
|
|
||||||
local co = coroutine.create(f)
|
|
||||||
session_coroutine_id[co] = session
|
|
||||||
session_coroutine_address[co] = source
|
|
||||||
suspend(co, coroutine.resume(co, session,source, p.unpack(msg,sz)))
|
|
||||||
else
|
|
||||||
print("Unknown request :" , p.unpack(msg,sz))
|
|
||||||
error(string.format("Can't dispatch type %s : ", p.name))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local p = assert(proto[prototype], prototype)
|
||||||
|
local f = p.dispatch
|
||||||
|
if f then
|
||||||
|
local co = coroutine.create(f)
|
||||||
|
session_coroutine_id[co] = session
|
||||||
|
session_coroutine_address[co] = source
|
||||||
|
suspend(co, coroutine.resume(co, session,source, p.unpack(msg,sz, ...)))
|
||||||
|
else
|
||||||
|
print("Unknown request :" , p.unpack(msg,sz))
|
||||||
|
error(string.format("Can't dispatch type %s : ", p.name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.filter(f ,start)
|
||||||
|
c.callback(function(...)
|
||||||
|
dispatch_message(f(...))
|
||||||
|
end)
|
||||||
|
skynet.timeout(0, function()
|
||||||
|
start()
|
||||||
|
skynet.send(".launcher","lua", nil)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -382,7 +396,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.start(f)
|
function skynet.start(f)
|
||||||
start_skynet()
|
c.callback(dispatch_message)
|
||||||
skynet.timeout(0, function()
|
skynet.timeout(0, function()
|
||||||
f()
|
f()
|
||||||
skynet.send(".launcher","lua", nil)
|
skynet.send(".launcher","lua", nil)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ skynet.start(function()
|
|||||||
local watchdog = skynet.launch("snlua","watchdog","8888 4 0")
|
local watchdog = skynet.launch("snlua","watchdog","8888 4 0")
|
||||||
local db = skynet.launch("snlua","simpledb")
|
local db = skynet.launch("snlua","simpledb")
|
||||||
local redis = skynet.launch("snlua","redis-mgr")
|
local redis = skynet.launch("snlua","redis-mgr")
|
||||||
skynet.launch("snlua","testgroup")
|
-- skynet.launch("snlua","testgroup")
|
||||||
|
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user