This commit is contained in:
duanhf2012
2022-01-20 14:44:38 +08:00
parent a3c36e7690
commit b54b9e40d5

View File

@@ -59,6 +59,8 @@ type RpcHandler struct {
mapRawFunctions map[uint32] RawRpcCallBack mapRawFunctions map[uint32] RawRpcCallBack
funcRpcClient FuncRpcClient funcRpcClient FuncRpcClient
funcRpcServer FuncRpcServer funcRpcServer FuncRpcServer
pClientList []*Client
} }
type TriggerRpcEvent func(bConnect bool,clientSeq uint32,nodeId int) type TriggerRpcEvent func(bConnect bool,clientSeq uint32,nodeId int)
@@ -107,7 +109,7 @@ func (handler *RpcHandler) InitRpcHandler(rpcHandler IRpcHandler,getClientFun Fu
handler.mapFunctions = map[string]RpcMethodInfo{} handler.mapFunctions = map[string]RpcMethodInfo{}
handler.funcRpcClient = getClientFun handler.funcRpcClient = getClientFun
handler.funcRpcServer = getServerFun handler.funcRpcServer = getServerFun
handler.pClientList = make([]*Client,maxClusterNode)
handler.RegisterRpc(rpcHandler) handler.RegisterRpc(rpcHandler)
} }
@@ -542,8 +544,7 @@ func (handler *RpcHandler) CastGo(serviceMethod string,args interface{}) error{
func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs IRawInputArgs) error { func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs IRawInputArgs) error {
processor := GetProcessor(uint8(rpcProcessorType)) processor := GetProcessor(uint8(rpcProcessorType))
var pClientList [maxClusterNode]*Client err,count := handler.funcRpcClient(nodeId,serviceName,handler.pClientList)
err,count := handler.funcRpcClient(nodeId,serviceName,pClientList[:])
if count==0||err != nil { if count==0||err != nil {
//args.DoGc() //args.DoGc()
log.SError("Call serviceMethod is error:",err.Error()) log.SError("Call serviceMethod is error:",err.Error())
@@ -559,7 +560,7 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId in
//2.rpcClient调用 //2.rpcClient调用
//如果调用本结点服务 //如果调用本结点服务
for i:=0;i<count;i++{ for i:=0;i<count;i++{
if pClientList[i].bSelfNode == true { if handler.pClientList[i].bSelfNode == true {
pLocalRpcServer:= handler.funcRpcServer() pLocalRpcServer:= handler.funcRpcServer()
//调用自己rpcHandler处理器 //调用自己rpcHandler处理器
if serviceName == handler.rpcHandler.GetName() { //自己服务调用 if serviceName == handler.rpcHandler.GetName() { //自己服务调用
@@ -569,23 +570,23 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId in
} }
//其他的rpcHandler的处理器 //其他的rpcHandler的处理器
pCall := pLocalRpcServer.selfNodeRpcHandlerGo(processor,pClientList[i],true,serviceName,rpcMethodId,serviceName,nil,nil,rawArgs.GetRawData()) pCall := pLocalRpcServer.selfNodeRpcHandlerGo(processor,handler.pClientList[i],true,serviceName,rpcMethodId,serviceName,nil,nil,rawArgs.GetRawData())
rawArgs.DoEscape() rawArgs.DoEscape()
if pCall.Err!=nil { if pCall.Err!=nil {
err = pCall.Err err = pCall.Err
} }
pClientList[i].RemovePending(pCall.Seq) handler.pClientList[i].RemovePending(pCall.Seq)
ReleaseCall(pCall) ReleaseCall(pCall)
continue continue
} }
//跨node调用 //跨node调用
pCall := pClientList[i].RawGo(processor,true,rpcMethodId,serviceName,rawArgs.GetRawData(),nil) pCall := handler.pClientList[i].RawGo(processor,true,rpcMethodId,serviceName,rawArgs.GetRawData(),nil)
rawArgs.DoFree() rawArgs.DoFree()
if pCall.Err!=nil { if pCall.Err!=nil {
err = pCall.Err err = pCall.Err
} }
pClientList[i].RemovePending(pCall.Seq) handler.pClientList[i].RemovePending(pCall.Seq)
ReleaseCall(pCall) ReleaseCall(pCall)
} }