connectTLS returns a tls.Conn that has already completed the Handshake.
(ctx context.Context, conn net.Conn, config *tls.Config)
| 239 | |
| 240 | // connectTLS returns a tls.Conn that has already completed the Handshake. |
| 241 | func (d *Dialer) connectTLS(ctx context.Context, conn net.Conn, config *tls.Config) (tlsConn *tls.Conn, err error) { |
| 242 | tlsConn = tls.Client(conn, config) |
| 243 | errch := make(chan error) |
| 244 | |
| 245 | go func() { |
| 246 | defer close(errch) |
| 247 | errch <- tlsConn.Handshake() |
| 248 | }() |
| 249 | |
| 250 | select { |
| 251 | case <-ctx.Done(): |
| 252 | conn.Close() |
| 253 | tlsConn.Close() |
| 254 | <-errch // ignore possible error from Handshake |
| 255 | err = ctx.Err() |
| 256 | |
| 257 | case err = <-errch: |
| 258 | } |
| 259 | |
| 260 | return |
| 261 | } |
| 262 | |
| 263 | // connect opens a socket connection to the broker, wraps it to create a |
| 264 | // kafka connection, and performs SASL authentication if configured to do so. |