RPCClient 支持在主线程接收消息

This commit is contained in:
baidwwy 2021-05-03 22:03:31 +08:00
parent 81307427f9
commit 0f8d0c4746
4 changed files with 28 additions and 9 deletions

View File

@ -1,10 +1,10 @@
--[[
@Author : GGELUA
@Date : 2021-02-11 11:49:09
@LastEditTime : 2021-04-25 14:36:39
@LastEditTime : 2021-05-03 20:23:00
--]]
local PushClient = package.loaded.PushClient or require("HPS/PushClient")
local PushClient = require("HPS/PushClient")
local PackClient = class("PackClient",PushClient)
PackClient._hp = false
PackClient._接收事件 = false

View File

@ -1,10 +1,10 @@
--[[
@Author : GGELUA
@Date : 2021-02-11 11:49:09
@LastEditTime : 2021-05-02 11:21:25
@LastEditTime : 2021-05-03 20:23:10
--]]
local Socket = package.loaded.Socket or require("HPS/Socket")
local Socket = require("HPS.Socket")
local PackServer = class("PackServer",Socket)
PackServer._hp = false
PackServer._准备事件 = false

View File

@ -1,7 +1,7 @@
--[[
@Author : baidwwy
@Date : 2021-02-11 11:49:09
@LastEditTime : 2021-04-25 14:34:50
@LastEditTime : 2021-05-03 20:26:53
--]]
local adler32 = require("zlib").adler32
@ -14,13 +14,18 @@ local c_yield = coroutine.yield
local c_resume = coroutine.resume
local c_create = coroutine.create
local t_unpack = table.unpack
local PackClient = package.loaded.PackClient or require("HPS/PackClient")
local next = next
local PackClient = require("HPS.PackClient")
local RPCClient = class("RPCClient",PackClient)
local _REG = setmetatable({}, {__mode="k"})
local _CBK = setmetatable({}, {__mode="k"})
function RPCClient:RPCClient()
function RPCClient:RPCClient(mcall)
if mcall and then
self._mcall = {}
:(self)
end
PackClient.PackClient(self)--初始化父类
local reg = {}
_REG[self] = reg--private 注册表
@ -36,6 +41,15 @@ function RPCClient:RPCClient()
})
end
function RPCClient:更新事件()
if next(self._mcall) then
for i,v in ipairs(self._mcall) do
self:_接收事件(nil,v)
end
self._mcall = {}
end
end
function RPCClient:__index(k)--调用方法
local co,main = c_runing()
local funp = type(k)=='string' and adler32(k) or k
@ -65,6 +79,10 @@ function RPCClient:_接收事件(id,data)
self:(id,data)
return
end
if self._mcall and id then
table.insert(self._mcall,data)
return
end
local t = m_unpack(data)
if type(t)=='table' then
local funp,cop = t[1],t[2]

View File

@ -1,7 +1,7 @@
--[[
@Author : baidwwy
@Date : 2021-02-11 11:49:09
@LastEditTime : 2021-04-25 14:35:04
@LastEditTime : 2021-05-03 20:22:33
--]]
local adler32 = require("zlib").adler32
@ -14,7 +14,8 @@ local c_yield = coroutine.yield
local c_resume = coroutine.resume
local c_create = coroutine.create
local t_unpack = table.unpack
local PackServer = package.loaded.PackServer or require("HPS/PackServer")
local PackServer = require("HPS.PackServer")
local RPCServer = class("RPCServer",PackServer)
local _REG = setmetatable({}, {__mode="k"})--接收函数