// Copyright 2019 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package proxyimport ()// A ContextDialer dials using a context.typeContextDialerinterface {DialContext(ctx context.Context, network, address string) (net.Conn, error)}// Dial works like DialContext on net.Dialer but using a dialer returned by FromEnvironment.//// The passed ctx is only used for returning the Conn, not the lifetime of the Conn.//// Custom dialers (registered via RegisterDialerType) that do not implement ContextDialer// can leak a goroutine for as long as it takes the underlying Dialer implementation to timeout.//// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.func ( context.Context, , string) (net.Conn, error) { := FromEnvironment()if , := .(ContextDialer); {return .DialContext(, , ) }returndialContext(, , , )}// WARNING: this can leak a goroutine for as long as the underlying Dialer implementation takes to timeout// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.func ( context.Context, Dialer, , string) (net.Conn, error) {var (net.Conn = make(chanstruct{}, 1)error )gofunc() { , = .Dial(, )close()if != nil && .Err() != nil { .Close() } }()select {case<-.Done(): = .Err()case<-: }return , }
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.