complete cluster.send

This commit is contained in:
Cloud Wu
2017-03-25 00:10:23 +08:00
parent 3a4a673b43
commit 6289b2b8e4
7 changed files with 90 additions and 23 deletions

View File

@@ -91,6 +91,21 @@ function command.req(...)
end
end
function command.push(source, node, addr, msg, sz)
local session = node_session[node] or 1
local request, new_session, padding = cluster.packpush(addr, session, msg, sz)
if padding then -- is multi push
node_session[node] = new_session
end
-- node_channel[node] may yield or throw error
local c = node_channel[node]
c:request(request, nil, padding)
-- notice: push may fail where the channel is disconnected or broken.
end
local proxy = {}
function command.proxy(source, node, name)
@@ -121,9 +136,9 @@ local large_request = {}
function command.socket(source, subcmd, fd, msg)
if subcmd == "data" then
local sz
local addr, session, msg, padding = cluster.unpackrequest(msg)
local addr, session, msg, padding, is_push = cluster.unpackrequest(msg)
if padding then
local req = large_request[session] or { addr = addr }
local req = large_request[session] or { addr = addr , is_push = is_push }
large_request[session] = req
table.insert(req, msg)
return
@@ -134,6 +149,7 @@ function command.socket(source, subcmd, fd, msg)
table.insert(req, msg)
msg,sz = cluster.concat(req)
addr = req.addr
is_push = req.is_push
end
if not msg then
local response = cluster.packresponse(session, false, "Invalid large req")
@@ -152,6 +168,9 @@ function command.socket(source, subcmd, fd, msg)
ok = false
msg = "name not found"
end
elseif is_push then
skynet.rawsend(addr, "lua", msg, sz)
return -- no response
else
ok , msg, sz = pcall(skynet.rawcall, addr, "lua", msg, sz)
end