diff options
author | Ian Lance Taylor <iant@golang.org> | 2018-09-24 21:46:21 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-09-24 21:46:21 +0000 |
commit | dd931d9b48647e898dc80927c532ae93cc09e192 (patch) | |
tree | 71be2295cd79b8a182f6130611658db8628772d5 /libgo/go/net/lookup.go | |
parent | 779d8a5ad09b01428726ea5a0e6c87bd9ac3c0e4 (diff) |
libgo: update to Go 1.11
Reviewed-on: https://go-review.googlesource.com/136435
gotools/:
* Makefile.am (mostlyclean-local): Run chmod on check-go-dir to
make sure it is writable.
(check-go-tools): Likewise.
(check-vet): Copy internal/objabi to check-vet-dir.
* Makefile.in: Rebuild.
From-SVN: r264546
Diffstat (limited to 'libgo/go/net/lookup.go')
-rw-r--r-- | libgo/go/net/lookup.go | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go index a65b735f921..e0f21fa9a8d 100644 --- a/libgo/go/net/lookup.go +++ b/libgo/go/net/lookup.go @@ -15,7 +15,7 @@ import ( // names and numbers for platforms that don't have a complete list of // protocol numbers. // -// See http://www.iana.org/assignments/protocol-numbers +// See https://www.iana.org/assignments/protocol-numbers // // On Unix, this map is augmented by readProtocols via lookupProtocol. var protocols = map[string]int{ @@ -133,10 +133,25 @@ type Resolver struct { // If nil, the default dialer is used. Dial func(ctx context.Context, network, address string) (Conn, error) + // lookupGroup merges LookupIPAddr calls together for lookups for the same + // host. The lookupGroup key is the LookupIPAddr.host argument. + // The return values are ([]IPAddr, error). + lookupGroup singleflight.Group + // TODO(bradfitz): optional interface impl override hook // TODO(bradfitz): Timeout time.Duration? } +func (r *Resolver) preferGo() bool { return r != nil && r.PreferGo } +func (r *Resolver) strictErrors() bool { return r != nil && r.StrictErrors } + +func (r *Resolver) getLookupGroup() *singleflight.Group { + if r == nil { + return &DefaultResolver.lookupGroup + } + return &r.lookupGroup +} + // LookupHost looks up the given host using the local resolver. // It returns a slice of that host's addresses. func LookupHost(host string) (addrs []string, err error) { @@ -147,11 +162,11 @@ func LookupHost(host string) (addrs []string, err error) { // It returns a slice of that host's addresses. func (r *Resolver) LookupHost(ctx context.Context, host string) (addrs []string, err error) { // Make sure that no matter what we do later, host=="" is rejected. - // ParseIP, for example, does accept empty strings. + // parseIP, for example, does accept empty strings. if host == "" { return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host} } - if ip := ParseIP(host); ip != nil { + if ip, _ := parseIPZone(host); ip != nil { return []string{host}, nil } return r.lookupHost(ctx, host) @@ -175,12 +190,12 @@ func LookupIP(host string) ([]IP, error) { // It returns a slice of that host's IPv4 and IPv6 addresses. func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, error) { // Make sure that no matter what we do later, host=="" is rejected. - // ParseIP, for example, does accept empty strings. + // parseIP, for example, does accept empty strings. if host == "" { return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host} } - if ip := ParseIP(host); ip != nil { - return []IPAddr{{IP: ip}}, nil + if ip, zone := parseIPZone(host); ip != nil { + return []IPAddr{{IP: ip, Zone: zone}}, nil } trace, _ := ctx.Value(nettrace.TraceKey{}).(*nettrace.Trace) if trace != nil && trace.DNSStart != nil { @@ -201,7 +216,7 @@ func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, err lookupGroupCtx, lookupGroupCancel := context.WithCancel(context.Background()) dnsWaitGroup.Add(1) - ch, called := lookupGroup.DoChan(host, func() (interface{}, error) { + ch, called := r.getLookupGroup().DoChan(host, func() (interface{}, error) { defer dnsWaitGroup.Done() return testHookLookupIP(lookupGroupCtx, resolverFunc, host) }) @@ -218,7 +233,7 @@ func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, err // let the lookup continue uncanceled, and let later // lookups with the same key share the result. // See issues 8602, 20703, 22724. - if lookupGroup.ForgetUnshared(host) { + if r.getLookupGroup().ForgetUnshared(host) { lookupGroupCancel() } else { go func() { @@ -241,12 +256,6 @@ func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, err } } -// lookupGroup merges LookupIPAddr calls together for lookups -// for the same host. The lookupGroup key is is the LookupIPAddr.host -// argument. -// The return values are ([]IPAddr, error). -var lookupGroup singleflight.Group - // lookupIPReturn turns the return values from singleflight.Do into // the return values from LookupIP. func lookupIPReturn(addrsi interface{}, err error, shared bool) ([]IPAddr, error) { |