增加动态调用rpc并增加rpc调用超时时间

This commit is contained in:
boyce
2019-05-15 14:09:47 +08:00
parent e5c92f981d
commit 67d3eec964
2 changed files with 10 additions and 1 deletions

View File

@@ -500,7 +500,7 @@ func GetNodeName(nodeid int) string {
}
func DynamicCall(address string, serviceMethod string, args interface{}, reply interface{}) error {
rpcClient, err := rpc.Dial("tcp", address)
rpcClient, err := rpc.DialTimeOut("tcp", address, time.Second*1)
if err != nil {
return err
}

View File

@@ -291,7 +291,16 @@ func Dial(network, address string) (*Client, error) {
}
tcpconn, _ := conn.(*net.TCPConn)
tcpconn.SetNoDelay(true)
return NewClient(conn), nil
}
func DialTimeOut(network, address string, timeout time.Duration) (*Client, error) {
conn, err := net.DialTimeout(network, address, timeout)
if err != nil {
return nil, err
}
tcpconn, _ := conn.(*net.TCPConn)
tcpconn.SetNoDelay(true)
return NewClient(conn), nil
}