mirror of
https://github.com/golang/go.git
synced 2025-11-11 22:21:06 +00:00
net: use Go's DNS resolver when system configuration permits
If the machine's network configuration files (resolv.conf, nsswitch.conf) don't have any unsupported options, prefer Go's DNS resolver, which doesn't have the cgo & thread over. It means users can have more than 500 DNS requests outstanding (our current limit for cgo lookups) and not have one blocked thread per outstanding request. Discussed in thread https://groups.google.com/d/msg/golang-dev/2ZUi792oztM/Q0rg_DkF5HMJ Change-Id: I3f685d70aff6b47bec30b63e9fba674b20507f95 Reviewed-on: https://go-review.googlesource.com/8945 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
c231228085
commit
4a0ba7aa17
10 changed files with 1079 additions and 53 deletions
|
|
@ -49,20 +49,28 @@ func lookupProtocol(name string) (int, error) {
|
|||
return proto, nil
|
||||
}
|
||||
|
||||
func lookupHost(host string) ([]string, error) {
|
||||
addrs, err, ok := cgoLookupHost(host)
|
||||
if !ok {
|
||||
addrs, err = goLookupHost(host)
|
||||
func lookupHost(host string) (addrs []string, err error) {
|
||||
order := systemConf().hostLookupOrder(host)
|
||||
if order == hostLookupCgo {
|
||||
if addrs, err, ok := cgoLookupHost(host); ok {
|
||||
return addrs, err
|
||||
}
|
||||
// cgo not available (or netgo); fall back to Go's DNS resolver
|
||||
order = hostLookupFilesDNS
|
||||
}
|
||||
return addrs, err
|
||||
return goLookupHostOrder(host, order)
|
||||
}
|
||||
|
||||
func lookupIP(host string) ([]IPAddr, error) {
|
||||
addrs, err, ok := cgoLookupIP(host)
|
||||
if !ok {
|
||||
addrs, err = goLookupIP(host)
|
||||
func lookupIP(host string) (addrs []IPAddr, err error) {
|
||||
order := systemConf().hostLookupOrder(host)
|
||||
if order == hostLookupCgo {
|
||||
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 addrs, err
|
||||
return goLookupIPOrder(host, order)
|
||||
}
|
||||
|
||||
func lookupPort(network, service string) (int, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue