2013-07-14 07:22:41 -04:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2013-07-14 07:31:51 -04:00
|
|
|
"time"
|
2013-07-14 07:22:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConnectFunc is a convenience method for returning a function
|
|
|
|
// that just uses net.Dial to communicate with the remote end that
|
|
|
|
// is suitable for use with the SSH communicator configuration.
|
2013-08-22 14:53:31 -04:00
|
|
|
func ConnectFunc(network, addr string) func() (net.Conn, error) {
|
2013-07-14 07:22:41 -04:00
|
|
|
return func() (net.Conn, error) {
|
2014-02-21 17:45:40 -05:00
|
|
|
c, err := net.DialTimeout(network, addr, 15*time.Second)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if tcpConn, ok := c.(*net.TCPConn); ok {
|
|
|
|
tcpConn.SetKeepAlive(true)
|
2014-09-04 14:24:01 -04:00
|
|
|
tcpConn.SetKeepAlivePeriod(5 * time.Second)
|
2014-02-21 17:45:40 -05:00
|
|
|
}
|
2014-02-21 17:51:33 -05:00
|
|
|
|
|
|
|
return c, nil
|
2013-07-14 07:22:41 -04:00
|
|
|
}
|
|
|
|
}
|