From 0475edbf9e17bf1dc21832cbcbb5738398f93760 Mon Sep 17 00:00:00 2001 From: boyce Date: Fri, 8 Jan 2021 11:01:09 +0800 Subject: [PATCH] =?UTF-8?q?rpc=E5=86=85=E5=AD=98=E6=B1=A0=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/rpc.go | 2 +- rpc/rpchandler.go | 8 ++++---- util/sync/MemPool.go | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rpc/rpc.go b/rpc/rpc.go index 296f496..92d0547 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -144,7 +144,7 @@ func (call *Call) Done() *Call{ } func MakeRpcRequest(rpcProcessor IRpcProcessor,seq uint64,rpcMethodId uint32,serviceMethod string,noReply bool,inParam []byte) *RpcRequest{ - rpcRequest := rpcRequestPool.Get().(*RpcRequest).Clear() + rpcRequest := rpcRequestPool.Get().(*RpcRequest) rpcRequest.rpcProcessor = rpcProcessor rpcRequest.RpcRequestData = rpcRequest.rpcProcessor.MakeRpcRequest(seq,rpcMethodId,serviceMethod,noReply,inParam) diff --git a/rpc/rpchandler.go b/rpc/rpchandler.go index 8e365e0..6b73ff7 100644 --- a/rpc/rpchandler.go +++ b/rpc/rpchandler.go @@ -243,12 +243,12 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) { request.requestHandle(nil,rpcErr) } } - - if request.requestHandle == nil { - ReleaseRpcRequest(request) - } }() + if request.requestHandle == nil { + defer ReleaseRpcRequest(request) + } + //如果是原始RPC请求 rawRpcId := request.RpcRequestData.GetRpcMethodId() if rawRpcId>0 { diff --git a/util/sync/MemPool.go b/util/sync/MemPool.go index 4a97b70..ace1748 100644 --- a/util/sync/MemPool.go +++ b/util/sync/MemPool.go @@ -1,6 +1,8 @@ package sync -import sysSync "sync" +import ( + sysSync "sync" +) type Pool struct { C chan interface{} //最大缓存的数量 @@ -36,6 +38,7 @@ func (pool *Pool) Put(data interface{}){ default: pool.syncPool.Put(data) } + } func NewPool(C chan interface{},New func()interface{}) *Pool{