github.com/enmand/kubernetes@v1.2.0-alpha.0/third_party/forked/coreos/go-etcd/etcd/client.go (about) 1 package etcd 2 3 import ( 4 "errors" 5 "net" 6 "time" 7 ) 8 9 // dial attempts to open a TCP connection to the provided address, explicitly 10 // enabling keep-alives with a one-second interval. 11 func Dial(network, addr string) (net.Conn, error) { 12 conn, err := net.DialTimeout(network, addr, time.Second) 13 if err != nil { 14 return nil, err 15 } 16 17 tcpConn, ok := conn.(*net.TCPConn) 18 if !ok { 19 return nil, errors.New("Failed type-assertion of net.Conn as *net.TCPConn") 20 } 21 22 // Keep TCP alive to check whether or not the remote machine is down 23 if err = tcpConn.SetKeepAlive(true); err != nil { 24 return nil, err 25 } 26 27 if err = tcpConn.SetKeepAlivePeriod(time.Second); err != nil { 28 return nil, err 29 } 30 31 return tcpConn, nil 32 }