Commit 26aa7422 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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/34014Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 2641cffd
......@@ -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() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment