mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-24 17:35:01 +01:00
796c5ad42d
transport/ssh: update go-netssh to new version => supports CloseWrite and Deadlines => build: require Go 1.11 (netssh requires it)
31 lines
576 B
Go
31 lines
576 B
Go
package tcp
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/zrepl/zrepl/config"
|
|
"github.com/zrepl/zrepl/transport"
|
|
)
|
|
|
|
type TCPConnecter struct {
|
|
Address string
|
|
dialer net.Dialer
|
|
}
|
|
|
|
func TCPConnecterFromConfig(in *config.TCPConnect) (*TCPConnecter, error) {
|
|
dialer := net.Dialer{
|
|
Timeout: in.DialTimeout,
|
|
}
|
|
|
|
return &TCPConnecter{in.Address, dialer}, nil
|
|
}
|
|
|
|
func (c *TCPConnecter) Connect(dialCtx context.Context) (transport.Wire, error) {
|
|
conn, err := c.dialer.DialContext(dialCtx, "tcp", c.Address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return conn.(*net.TCPConn), nil
|
|
}
|