From 67d3eec964a7fa2fbe978f301ce2a2dbd64d391f Mon Sep 17 00:00:00 2001 From: boyce Date: Wed, 15 May 2019 14:09:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81=E8=B0=83?= =?UTF-8?q?=E7=94=A8rpc=E5=B9=B6=E5=A2=9E=E5=8A=A0rpc=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster/cluster.go | 2 +- rpc/client.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index b96fa1d..2863349 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -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 } diff --git a/rpc/client.go b/rpc/client.go index 7825359..9a6137f 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -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 }