支持自定义日志,优化数据返回

This commit is contained in:
duanhf2012
2020-03-31 18:29:00 +08:00
parent 9e74d2bf2a
commit 5344da1276
5 changed files with 50 additions and 33 deletions

View File

@@ -70,7 +70,6 @@ func (slf *Client) AsycGo(rpcHandler IRpcHandler,mutiCoroutine bool,serviceMetho
request.Seq = slf.startSeq
slf.pending[call.Seq] = call
slf.pendingLock.Unlock()
request.ServiceMethod = serviceMethod
var herr error
request.InParam,herr = processor.Marshal(args)
@@ -163,8 +162,8 @@ func (slf *Client) Run(){
for {
bytes,err := slf.conn.ReadMsg()
if err != nil {
slf.Close()
slf.Start()
log.Error("rpcClient %s ReadMsg error:%+v",slf.Addr,err)
return
}
//1.解析head
respone := &RpcResponse{}
@@ -198,12 +197,7 @@ func (slf *Client) Run(){
}
}
}
func (slf *Client) OnClose(){
if slf.blocalhost== false{
//关闭时,重新连接
slf.Start()
}
}
}

View File

@@ -179,13 +179,16 @@ func (slf *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
v.iparam = request.localParam
}
var oParam reflect.Value
paramList = append(paramList,reflect.ValueOf(slf.GetRpcHandler())) //接受者
if request.localReply!=nil {
v.oParam = reflect.ValueOf(request.localReply)
oParam = reflect.ValueOf(request.localReply)
}else{
oParam = reflect.New(v.oParam.Type().Elem())
}
paramList = append(paramList,reflect.ValueOf(v.iparam))
paramList = append(paramList,v.oParam) //输出参数
paramList = append(paramList,oParam) //输出参数
returnValues := v.method.Func.Call(paramList)
errInter := returnValues[0].Interface()
@@ -194,7 +197,7 @@ func (slf *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
}
if request.requestHandle!=nil {
request.requestHandle(v.oParam.Interface(), err)
request.requestHandle(oParam.Interface(), err)
}
}