mirror of
https://github.com/golang/go.git
synced 2025-11-10 21:51:05 +00:00
net: context plumbing, add Dialer.DialContext
For #12580 (http.Transport tracing/analytics) Updates #13021 Change-Id: I126e494a7bd872e42c388ecb58499ecbf0f014cc Reviewed-on: https://go-review.googlesource.com/22101 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
This commit is contained in:
parent
1d0977a1d5
commit
b6b4004d5a
33 changed files with 521 additions and 381 deletions
|
|
@ -6,7 +6,10 @@
|
|||
|
||||
package net
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var onceReadProtocols sync.Once
|
||||
|
||||
|
|
@ -49,7 +52,7 @@ func lookupProtocol(name string) (int, error) {
|
|||
return proto, nil
|
||||
}
|
||||
|
||||
func lookupHost(host string) (addrs []string, err error) {
|
||||
func lookupHost(ctx context.Context, host string) (addrs []string, err error) {
|
||||
order := systemConf().hostLookupOrder(host)
|
||||
if order == hostLookupCgo {
|
||||
if addrs, err, ok := cgoLookupHost(host); ok {
|
||||
|
|
@ -58,19 +61,20 @@ func lookupHost(host string) (addrs []string, err error) {
|
|||
// cgo not available (or netgo); fall back to Go's DNS resolver
|
||||
order = hostLookupFilesDNS
|
||||
}
|
||||
return goLookupHostOrder(host, order)
|
||||
return goLookupHostOrder(ctx, host, order)
|
||||
}
|
||||
|
||||
func lookupIP(host string) (addrs []IPAddr, err error) {
|
||||
func lookupIP(ctx context.Context, host string) (addrs []IPAddr, err error) {
|
||||
order := systemConf().hostLookupOrder(host)
|
||||
if order == hostLookupCgo {
|
||||
// TODO(bradfitz): push down ctx, or at least its deadline to start
|
||||
if addrs, err, ok := cgoLookupIP(host); ok {
|
||||
return addrs, err
|
||||
}
|
||||
// cgo not available (or netgo); fall back to Go's DNS resolver
|
||||
order = hostLookupFilesDNS
|
||||
}
|
||||
return goLookupIPOrder(host, order)
|
||||
return goLookupIPOrder(ctx, host, order)
|
||||
}
|
||||
|
||||
func lookupPort(network, service string) (int, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue