2018-12-11 22:01:50 +01:00
|
|
|
package tcp
|
2018-08-27 22:21:45 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
2018-12-11 22:01:50 +01:00
|
|
|
|
|
|
|
"github.com/zrepl/zrepl/config"
|
|
|
|
"github.com/zrepl/zrepl/transport"
|
2018-08-27 22:21:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-12-11 22:01:50 +01:00
|
|
|
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
|
2018-08-27 22:21:45 +02:00
|
|
|
}
|