优化rpc非异步接口

This commit is contained in:
duanhf2012
2020-04-02 16:47:44 +08:00
parent 649b9bee64
commit aba29eab01

View File

@@ -6,6 +6,7 @@ import (
"github.com/duanhf2012/origin/network" "github.com/duanhf2012/origin/network"
"math" "math"
"reflect" "reflect"
"runtime"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -157,6 +158,15 @@ type RpcResponse struct {
func (slf *Client) Run(){ func (slf *Client) Run(){
defer func() {
if r := recover(); r != nil {
buf := make([]byte, 4096)
l := runtime.Stack(buf, false)
err := fmt.Errorf("%v: %s\n", r, buf[:l])
log.Error("core dump info:%+v",err)
}
}()
for { for {
bytes,err := slf.conn.ReadMsg() bytes,err := slf.conn.ReadMsg()
if err != nil { if err != nil {
@@ -193,7 +203,7 @@ func (slf *Client) Run(){
v.Err= respone.Err v.Err= respone.Err
} }
if v.callback.IsValid() { if v.callback!=nil && v.callback.IsValid() {
v.rpcHandler.(*RpcHandler).callResponeCallBack<-v v.rpcHandler.(*RpcHandler).callResponeCallBack<-v
}else{ }else{
v.done <- v v.done <- v