summaryrefslogtreecommitdiff
path: root/libgo/go/net/lookup.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-10-31 00:59:47 +0000
commitaf146490bb04205107cb23e301ec7a8ff927b5fc (patch)
tree13beeaed3698c61903fe93fb1ce70bd9b18d4e7f /libgo/go/net/lookup.go
parent725e1be3406315d9bcc8195d7eef0a7082b3c7cc (diff)
runtime: Remove now unnecessary pad field from ParFor.
It is not needed due to the removal of the ctx field. Reviewed-on: https://go-review.googlesource.com/16525 From-SVN: r229616
Diffstat (limited to 'libgo/go/net/lookup.go')
-rw-r--r--libgo/go/net/lookup.go59
1 files changed, 43 insertions, 16 deletions
diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go
index aeffe6c9b72..a7ceee823f1 100644
--- a/libgo/go/net/lookup.go
+++ b/libgo/go/net/lookup.go
@@ -4,7 +4,10 @@
package net
-import "time"
+import (
+ "internal/singleflight"
+ "time"
+)
// protocols contains minimal mappings between internet protocol
// names and numbers for platforms that don't have a complete list of
@@ -22,36 +25,60 @@ var protocols = map[string]int{
// LookupHost looks up the given host using the local resolver.
// It returns an array of that host's addresses.
func LookupHost(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.
+ if host == "" {
+ return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host}
+ }
+ if ip := ParseIP(host); ip != nil {
+ return []string{host}, nil
+ }
return lookupHost(host)
}
// LookupIP looks up host using the local resolver.
// It returns an array of that host's IPv4 and IPv6 addresses.
-func LookupIP(host string) (addrs []IP, err error) {
- return lookupIPMerge(host)
+func LookupIP(host string) (ips []IP, err error) {
+ // Make sure that no matter what we do later, host=="" is rejected.
+ // ParseIP, for example, does accept empty strings.
+ if host == "" {
+ return nil, &DNSError{Err: errNoSuchHost.Error(), Name: host}
+ }
+ if ip := ParseIP(host); ip != nil {
+ return []IP{ip}, nil
+ }
+ addrs, err := lookupIPMerge(host)
+ if err != nil {
+ return
+ }
+ ips = make([]IP, len(addrs))
+ for i, addr := range addrs {
+ ips[i] = addr.IP
+ }
+ return
}
-var lookupGroup singleflight
+var lookupGroup singleflight.Group
// lookupIPMerge wraps lookupIP, but makes sure that for any given
// host, only one lookup is in-flight at a time. The returned memory
// is always owned by the caller.
-func lookupIPMerge(host string) (addrs []IP, err error) {
+func lookupIPMerge(host string) (addrs []IPAddr, err error) {
addrsi, err, shared := lookupGroup.Do(host, func() (interface{}, error) {
- return lookupIP(host)
+ return testHookLookupIP(lookupIP, host)
})
return lookupIPReturn(addrsi, err, shared)
}
// lookupIPReturn turns the return values from singleflight.Do into
// the return values from LookupIP.
-func lookupIPReturn(addrsi interface{}, err error, shared bool) ([]IP, error) {
+func lookupIPReturn(addrsi interface{}, err error, shared bool) ([]IPAddr, error) {
if err != nil {
return nil, err
}
- addrs := addrsi.([]IP)
+ addrs := addrsi.([]IPAddr)
if shared {
- clone := make([]IP, len(addrs))
+ clone := make([]IPAddr, len(addrs))
copy(clone, addrs)
addrs = clone
}
@@ -59,7 +86,7 @@ func lookupIPReturn(addrsi interface{}, err error, shared bool) ([]IP, error) {
}
// lookupIPDeadline looks up a hostname with a deadline.
-func lookupIPDeadline(host string, deadline time.Time) (addrs []IP, err error) {
+func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err error) {
if deadline.IsZero() {
return lookupIPMerge(host)
}
@@ -76,7 +103,7 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IP, err error) {
defer t.Stop()
ch := lookupGroup.DoChan(host, func() (interface{}, error) {
- return lookupIP(host)
+ return testHookLookupIP(lookupIP, host)
})
select {
@@ -90,7 +117,7 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IP, err error) {
return nil, errTimeout
case r := <-ch:
- return lookupIPReturn(r.v, r.err, r.shared)
+ return lookupIPReturn(r.Val, r.Err, r.Shared)
}
}
@@ -121,22 +148,22 @@ func LookupSRV(service, proto, name string) (cname string, addrs []*SRV, err err
}
// LookupMX returns the DNS MX records for the given domain name sorted by preference.
-func LookupMX(name string) (mx []*MX, err error) {
+func LookupMX(name string) (mxs []*MX, err error) {
return lookupMX(name)
}
// LookupNS returns the DNS NS records for the given domain name.
-func LookupNS(name string) (ns []*NS, err error) {
+func LookupNS(name string) (nss []*NS, err error) {
return lookupNS(name)
}
// LookupTXT returns the DNS TXT records for the given domain name.
-func LookupTXT(name string) (txt []string, err error) {
+func LookupTXT(name string) (txts []string, err error) {
return lookupTXT(name)
}
// LookupAddr performs a reverse lookup for the given address, returning a list
// of names mapping to that address.
-func LookupAddr(addr string) (name []string, err error) {
+func LookupAddr(addr string) (names []string, err error) {
return lookupAddr(addr)
}