Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ type Config struct {
// hung connections.
DisableEPSV bool

// Overrides the net.Dial method to allow for customised network connections.
DialFunc func(network string, address string) (net.Conn, error)

// For testing convenience.
stubResponses map[string]stubResponse
}
Expand Down Expand Up @@ -369,15 +372,20 @@ func (c *Client) openConn(idx int, host string) (pconn *persistentConn, err erro

var conn net.Conn

if c.config.TLSConfig != nil && c.config.TLSMode == TLSImplicit {
pconn.debug("opening TLS control connection to %s", host)
dialer := &net.Dialer{
Timeout: c.config.Timeout,
}
conn, err = tls.DialWithDialer(dialer, "tcp", host, pconn.config.TLSConfig)
if c.config.DialFunc != nil {
pconn.debug("opening control connection to %s via DialFunc", host)
conn, err = c.config.DialFunc("tcp", host)
} else {
pconn.debug("opening control connection to %s", host)
conn, err = net.DialTimeout("tcp", host, c.config.Timeout)
if c.config.TLSConfig != nil && c.config.TLSMode == TLSImplicit {
pconn.debug("opening TLS control connection to %s", host)
dialer := &net.Dialer{
Timeout: c.config.Timeout,
}
conn, err = tls.DialWithDialer(dialer, "tcp", host, pconn.config.TLSConfig)
} else {
pconn.debug("opening control connection to %s", host)
conn, err = net.DialTimeout("tcp", host, c.config.Timeout)
}
}

var (
Expand Down
12 changes: 10 additions & 2 deletions persistent_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,16 @@ func (pconn *persistentConn) prepareDataConn() (func() (net.Conn, error), error)
return nil, err
}

pconn.debug("opening data connection to %s", host)
dc, netErr := net.DialTimeout("tcp", host, pconn.config.Timeout)
var dc net.Conn
var netErr error

if pconn.config.DialFunc != nil {
pconn.debug("opening data connection to %s via DialFunc", host)
dc, netErr = pconn.config.DialFunc("tcp", host)
} else {
pconn.debug("opening data connection to %s", host)
dc, netErr = net.DialTimeout("tcp", host, pconn.config.Timeout)
}

if netErr != nil {
var isTemporary bool
Expand Down