mirror of
https://github.com/golang/go
synced 2024-09-30 10:18:32 -06:00
net: use baked-in port numbers as fallback if cgo port lookup fails
Fixes TestLookupPort_Minimal on android. Fixes #18213 Change-Id: I1b65e790525d339a4cb7f17afe7e3a02c4587302 Reviewed-on: https://go-review.googlesource.com/34014 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
2641cffd41
commit
26aa7422e5
@ -76,13 +76,15 @@ func (r *Resolver) lookupIP(ctx context.Context, host string) (addrs []IPAddr, e
|
||||
}
|
||||
|
||||
func (r *Resolver) 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 !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
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,11 @@ package net
|
||||
|
||||
import "sync"
|
||||
|
||||
var servicesError error
|
||||
var onceReadServices sync.Once
|
||||
|
||||
func readServices() {
|
||||
var file *file
|
||||
if file, servicesError = open("/etc/services"); servicesError != nil {
|
||||
file, err := open("/etc/services")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for line, ok := file.readLine(); ok; line, ok = file.readLine() {
|
||||
|
Loading…
Reference in New Issue
Block a user