diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-01-14 00:05:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 00:05:42 +0000 |
commit | c2047754c300b68c05d65faa8dc2925fe67b71b4 (patch) | |
tree | e183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/net/lookup_unix.go | |
parent | 829afb8f05602bb31c9c597b24df7377fed4f059 (diff) | |
download | gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.zip gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.gz gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.bz2 |
libgo: update to Go 1.8 release candidate 1
Compiler changes:
* Change map assignment to use mapassign and assign value directly.
* Change string iteration to use decoderune, faster for ASCII strings.
* Change makeslice to take int, and use makeslice64 for larger values.
* Add new noverflow field to hmap struct used for maps.
Unresolved problems, to be fixed later:
* Commented out test in go/types/sizes_test.go that doesn't compile.
* Commented out reflect.TestStructOf test for padding after zero-sized field.
Reviewed-on: https://go-review.googlesource.com/35231
gotools/:
Updates for Go 1.8rc1.
* Makefile.am (go_cmd_go_files): Add bug.go.
(s-zdefaultcc): Write defaultPkgConfig.
* Makefile.in: Rebuild.
From-SVN: r244456
Diffstat (limited to 'libgo/go/net/lookup_unix.go')
-rw-r--r-- | libgo/go/net/lookup_unix.go | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/libgo/go/net/lookup_unix.go b/libgo/go/net/lookup_unix.go index 15397e8..be2ced9 100644 --- a/libgo/go/net/lookup_unix.go +++ b/libgo/go/net/lookup_unix.go @@ -26,7 +26,7 @@ func readProtocols() { if len(f) < 2 { continue } - if proto, _, ok := dtoi(f[1], 0); ok { + if proto, _, ok := dtoi(f[1]); ok { if _, ok := protocols[f[0]]; !ok { protocols[f[0]] = proto } @@ -45,16 +45,12 @@ func readProtocols() { // returns correspondent protocol number. func lookupProtocol(_ context.Context, name string) (int, error) { onceReadProtocols.Do(readProtocols) - proto, found := protocols[name] - if !found { - return 0, &AddrError{Err: "unknown IP protocol specified", Addr: name} - } - return proto, nil + return lookupProtocolMap(name) } -func lookupHost(ctx context.Context, host string) (addrs []string, err error) { +func (r *Resolver) lookupHost(ctx context.Context, host string) (addrs []string, err error) { order := systemConf().hostLookupOrder(host) - if order == hostLookupCgo { + if !r.PreferGo && order == hostLookupCgo { if addrs, err, ok := cgoLookupHost(ctx, host); ok { return addrs, err } @@ -64,7 +60,10 @@ func lookupHost(ctx context.Context, host string) (addrs []string, err error) { return goLookupHostOrder(ctx, host, order) } -func lookupIP(ctx context.Context, host string) (addrs []IPAddr, err error) { +func (r *Resolver) lookupIP(ctx context.Context, host string) (addrs []IPAddr, err error) { + if r.PreferGo { + return goLookupIP(ctx, host) + } order := systemConf().hostLookupOrder(host) if order == hostLookupCgo { if addrs, err, ok := cgoLookupIP(ctx, host); ok { @@ -73,25 +72,28 @@ func lookupIP(ctx context.Context, host string) (addrs []IPAddr, err error) { // cgo not available (or netgo); fall back to Go's DNS resolver order = hostLookupFilesDNS } - return goLookupIPOrder(ctx, host, order) + addrs, _, err = goLookupIPCNAMEOrder(ctx, host, order) + return } -func lookupPort(ctx context.Context, network, service string) (int, error) { - // TODO: use the context if there ever becomes a need. Related - // is issue 15321. But port lookup generally just involves - // local files, and the os package has no context support. The - // files might be on a remote filesystem, though. This should - // probably race goroutines if ctx != context.Background(). - if systemConf().canUseCgo() { +func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int, error) { + if !r.PreferGo && systemConf().canUseCgo() { if port, err, ok := cgoLookupPort(ctx, network, service); ok { + if err != nil { + // Issue 18213: if cgo fails, first check to see whether we + // have the answer baked-in to the net package. + if port, err := goLookupPort(network, service); err == nil { + return port, nil + } + } return port, err } } return goLookupPort(network, service) } -func lookupCNAME(ctx context.Context, name string) (string, error) { - if systemConf().canUseCgo() { +func (r *Resolver) lookupCNAME(ctx context.Context, name string) (string, error) { + if !r.PreferGo && systemConf().canUseCgo() { if cname, err, ok := cgoLookupCNAME(ctx, name); ok { return cname, err } @@ -99,7 +101,7 @@ func lookupCNAME(ctx context.Context, name string) (string, error) { return goLookupCNAME(ctx, name) } -func lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) { +func (*Resolver) lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV, error) { var target string if service == "" && proto == "" { target = name @@ -119,7 +121,7 @@ func lookupSRV(ctx context.Context, service, proto, name string) (string, []*SRV return cname, srvs, nil } -func lookupMX(ctx context.Context, name string) ([]*MX, error) { +func (*Resolver) lookupMX(ctx context.Context, name string) ([]*MX, error) { _, rrs, err := lookup(ctx, name, dnsTypeMX) if err != nil { return nil, err @@ -133,7 +135,7 @@ func lookupMX(ctx context.Context, name string) ([]*MX, error) { return mxs, nil } -func lookupNS(ctx context.Context, name string) ([]*NS, error) { +func (*Resolver) lookupNS(ctx context.Context, name string) ([]*NS, error) { _, rrs, err := lookup(ctx, name, dnsTypeNS) if err != nil { return nil, err @@ -145,7 +147,7 @@ func lookupNS(ctx context.Context, name string) ([]*NS, error) { return nss, nil } -func lookupTXT(ctx context.Context, name string) ([]string, error) { +func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) { _, rrs, err := lookup(ctx, name, dnsTypeTXT) if err != nil { return nil, err @@ -157,8 +159,8 @@ func lookupTXT(ctx context.Context, name string) ([]string, error) { return txts, nil } -func lookupAddr(ctx context.Context, addr string) ([]string, error) { - if systemConf().canUseCgo() { +func (r *Resolver) lookupAddr(ctx context.Context, addr string) ([]string, error) { + if !r.PreferGo && systemConf().canUseCgo() { if ptrs, err, ok := cgoLookupPTR(ctx, addr); ok { return ptrs, err } |