(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config)
| 592 | } |
| 593 | |
| 594 | func dial(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config) (*Conn, error) { |
| 595 | if netDialer.Timeout != 0 { |
| 596 | var cancel context.CancelFunc |
| 597 | ctx, cancel = context.WithTimeout(ctx, netDialer.Timeout) |
| 598 | defer cancel() |
| 599 | } |
| 600 | |
| 601 | if !netDialer.Deadline.IsZero() { |
| 602 | var cancel context.CancelFunc |
| 603 | ctx, cancel = context.WithDeadline(ctx, netDialer.Deadline) |
| 604 | defer cancel() |
| 605 | } |
| 606 | |
| 607 | rawConn, err := netDialer.DialContext(ctx, network, addr) |
| 608 | if err != nil { |
| 609 | return nil, err |
| 610 | } |
| 611 | |
| 612 | colonPos := strings.LastIndex(addr, ":") |
| 613 | if colonPos == -1 { |
| 614 | colonPos = len(addr) |
| 615 | } |
| 616 | hostname := addr[:colonPos] |
| 617 | |
| 618 | if config == nil { |
| 619 | config = defaultConfig() |
| 620 | } |
| 621 | // If no ServerName is set, infer the ServerName |
| 622 | // from the hostname we're connecting to. |
| 623 | if config.ServerName == "" { |
| 624 | // Make a copy to avoid polluting argument or default. |
| 625 | c := config.Clone() |
| 626 | c.ServerName = hostname |
| 627 | config = c |
| 628 | } |
| 629 | |
| 630 | conn := Client(rawConn, config) |
| 631 | if err := conn.HandshakeContext(ctx); err != nil { |
| 632 | rawConn.Close() |
| 633 | return nil, err |
| 634 | } |
| 635 | return conn, nil |
| 636 | } |
| 637 | |
| 638 | // Dial connects to the given network address using net.Dial |
| 639 | // and then initiates a TLS handshake, returning the resulting |
no test coverage detected
searching dependent graphs…