From 3e47d2da3aea37bbab50b04c6f7bb2046f9d3f24 Mon Sep 17 00:00:00 2001 From: lifeiyi <736926938@qq.com> Date: Sat, 9 Jan 2021 16:57:23 +0800 Subject: [PATCH] =?UTF-8?q?RPC=E4=BC=A0=E8=BE=93=E5=8E=9F=E5=A7=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/rpc.go | 3 ++- rpc/rpchandler.go | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rpc/rpc.go b/rpc/rpc.go index 92d0547..cf911f1 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -53,7 +53,8 @@ type IRpcResponseData interface { type IRawInputArgs interface { GetRawData() []byte //获取原始数据 - DoGc() //处理完成,回收内存 + DoFree() //处理完成,回收内存 + DoEscape() //逃逸,GC自动回收 } type RpcHandleFinder interface { diff --git a/rpc/rpchandler.go b/rpc/rpchandler.go index 6b73ff7..7b895c9 100644 --- a/rpc/rpchandler.go +++ b/rpc/rpchandler.go @@ -87,7 +87,7 @@ type IRpcHandler interface { AsyncCallNode(nodeId int,serviceMethod string,args interface{},callback interface{}) error CallNode(nodeId int,serviceMethod string,args interface{},reply interface{}) error GoNode(nodeId int,serviceMethod string,args interface{}) error - RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs []byte) error + RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs IRawInputArgs) error CastGo(serviceMethod string,args interface{}) IsSingleCoroutine() bool UnmarshalInParam(rpcProcessor IRpcProcessor,serviceMethod string,rawRpcMethodId uint32,inParam []byte) (interface{},error) @@ -553,7 +553,7 @@ func (handler *RpcHandler) CastGo(serviceMethod string,args interface{}) { handler.goRpc(nil,true,0,serviceMethod,args) } -func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs []byte) error { +func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId int,rpcMethodId uint32,serviceName string,rawArgs IRawInputArgs) error { processor := GetProcessor(uint8(rpcProcessorType)) var pClientList [maxClusterNode]*Client err,count := handler.funcRpcClient(nodeId,serviceName,pClientList[:]) @@ -575,13 +575,14 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId in pLocalRpcServer:= handler.funcRpcServer() //调用自己rpcHandler处理器 if serviceName == handler.rpcHandler.GetName() { //自己服务调用 - err:= pLocalRpcServer.myselfRpcHandlerGo(serviceName,serviceName,rawArgs,nil) + err:= pLocalRpcServer.myselfRpcHandlerGo(serviceName,serviceName,rawArgs.GetRawData(),nil) //args.DoGc() return err } //其他的rpcHandler的处理器 - pCall := pLocalRpcServer.selfNodeRpcHandlerGo(processor,pClientList[i],true,serviceName,rpcMethodId,serviceName,nil,nil,rawArgs) + pCall := pLocalRpcServer.selfNodeRpcHandlerGo(processor,pClientList[i],true,serviceName,rpcMethodId,serviceName,nil,nil,rawArgs.GetRawData()) + rawArgs.DoEscape() if pCall.Err!=nil { err = pCall.Err } @@ -591,7 +592,8 @@ func (handler *RpcHandler) RawGoNode(rpcProcessorType RpcProcessorType,nodeId in } //跨node调用 - pCall := pClientList[i].RawGo(processor,true,rpcMethodId,serviceName,rawArgs,nil) + pCall := pClientList[i].RawGo(processor,true,rpcMethodId,serviceName,rawArgs.GetRawData(),nil) + rawArgs.DoFree() if pCall.Err!=nil { err = pCall.Err }