summaryrefslogtreecommitdiff
path: root/libgo/go/net/lookup.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-11-21 07:03:38 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-11-21 07:03:38 +0000
commitfabcaa8df3d6eb852b87821ef090d31d222870b7 (patch)
tree72455aea0286937aa08cc141e5efc800e4626577 /libgo/go/net/lookup.go
parenta51fb17f48428e7cfc96a72a9f9f87901363bb6b (diff)
libgo: Update to current version of master library.
From-SVN: r193688
Diffstat (limited to 'libgo/go/net/lookup.go')
-rw-r--r--libgo/go/net/lookup.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go
index 3a44e528eb2..bec93ec08cd 100644
--- a/libgo/go/net/lookup.go
+++ b/libgo/go/net/lookup.go
@@ -4,12 +4,53 @@
package net
+import (
+ "time"
+)
+
// 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) {
return lookupHost(host)
}
+func lookupHostDeadline(host string, deadline time.Time) (addrs []string, err error) {
+ if deadline.IsZero() {
+ return lookupHost(host)
+ }
+
+ // TODO(bradfitz): consider pushing the deadline down into the
+ // name resolution functions. But that involves fixing it for
+ // the native Go resolver, cgo, Windows, etc.
+ //
+ // In the meantime, just use a goroutine. Most users affected
+ // by http://golang.org/issue/2631 are due to TCP connections
+ // to unresponsive hosts, not DNS.
+ timeout := deadline.Sub(time.Now())
+ if timeout <= 0 {
+ err = errTimeout
+ return
+ }
+ t := time.NewTimer(timeout)
+ defer t.Stop()
+ type res struct {
+ addrs []string
+ err error
+ }
+ resc := make(chan res, 1)
+ go func() {
+ a, err := lookupHost(host)
+ resc <- res{a, err}
+ }()
+ select {
+ case <-t.C:
+ err = errTimeout
+ case r := <-resc:
+ addrs, err = r.addrs, r.err
+ }
+ return
+}
+
// 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) {
@@ -47,6 +88,11 @@ func LookupMX(name string) (mx []*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) {
+ return lookupNS(name)
+}
+
// LookupTXT returns the DNS TXT records for the given domain name.
func LookupTXT(name string) (txt []string, err error) {
return lookupTXT(name)