(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config)
| 118 | } |
| 119 | |
| 120 | func dial(ctx context.Context, netDialer *net.Dialer, network, addr string, config *Config) (*Conn, error) { |
| 121 | if netDialer.Timeout != 0 { |
| 122 | var cancel context.CancelFunc |
| 123 | ctx, cancel = context.WithTimeout(ctx, netDialer.Timeout) |
| 124 | defer cancel() |
| 125 | } |
| 126 | |
| 127 | if !netDialer.Deadline.IsZero() { |
| 128 | var cancel context.CancelFunc |
| 129 | ctx, cancel = context.WithDeadline(ctx, netDialer.Deadline) |
| 130 | defer cancel() |
| 131 | } |
| 132 | |
| 133 | rawConn, err := netDialer.DialContext(ctx, network, addr) |
| 134 | if err != nil { |
| 135 | return nil, err |
| 136 | } |
| 137 | |
| 138 | colonPos := strings.LastIndex(addr, ":") |
| 139 | if colonPos == -1 { |
| 140 | colonPos = len(addr) |
| 141 | } |
| 142 | hostname := addr[:colonPos] |
| 143 | |
| 144 | if config == nil { |
| 145 | config = defaultConfig() |
| 146 | } |
| 147 | // If no ServerName is set, infer the ServerName |
| 148 | // from the hostname we're connecting to. |
| 149 | if config.ServerName == "" { |
| 150 | // Make a copy to avoid polluting argument or default. |
| 151 | c := config.Clone() |
| 152 | c.ServerName = hostname |
| 153 | config = c |
| 154 | } |
| 155 | |
| 156 | conn := Client(rawConn, config) |
| 157 | if err := conn.HandshakeContext(ctx); err != nil { |
| 158 | rawConn.Close() |
| 159 | return nil, err |
| 160 | } |
| 161 | return conn, nil |
| 162 | } |
| 163 | |
| 164 | // Dial connects to the given network address using net.Dial |
| 165 | // and then initiates a TLS handshake, returning the resulting |
no test coverage detected
searching dependent graphs…