mirror of
https://github.com/golang/go.git
synced 2025-11-10 21:51:05 +00: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
2 changed files with 9 additions and 8 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue