github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/communicator/ssh/connect.go (about) 1 package ssh 2 3 import ( 4 "net" 5 "time" 6 ) 7 8 // ConnectFunc is a convenience method for returning a function 9 // that just uses net.Dial to communicate with the remote end that 10 // is suitable for use with the SSH communicator configuration. 11 func ConnectFunc(network, addr string) func() (net.Conn, error) { 12 return func() (net.Conn, error) { 13 c, err := net.DialTimeout(network, addr, 15*time.Second) 14 if err != nil { 15 return nil, err 16 } 17 18 if tcpConn, ok := c.(*net.TCPConn); ok { 19 tcpConn.SetKeepAlive(true) 20 } 21 22 return c, nil 23 } 24 }