diff options
| author | database64128 <free122448@hotmail.com> | 2025-08-23 04:55:42 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-08-28 16:10:24 -0700 |
| commit | ba1109feb515c2eb013399f53be5f17cfe1f189f (patch) | |
| tree | 4bb70e147e3a262d262d0301f1637901f056567a /src | |
| parent | f74ed44ed9be1708d4561e0fa667792ff2707c14 (diff) | |
| download | go-ba1109feb515c2eb013399f53be5f17cfe1f189f.tar.xz | |
net: remove redundant cgoLookupCNAME return parameter
`completed bool` just means `err == nil` after CL 446179.
While here, add a test for cgoLookupCNAME.
Co-authored-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Change-Id: I6081a089fde3cb27af4fbde6f04301fc3755272c
Reviewed-on: https://go-review.googlesource.com/c/go/+/698615
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Sean Liao <sean@liao.dev>
Reviewed-by: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/cgo_stub.go | 2 | ||||
| -rw-r--r-- | src/net/cgo_unix.go | 8 | ||||
| -rw-r--r-- | src/net/cgo_unix_test.go | 10 | ||||
| -rw-r--r-- | src/net/lookup_unix.go | 4 |
4 files changed, 17 insertions, 7 deletions
diff --git a/src/net/cgo_stub.go b/src/net/cgo_stub.go index a4f6b4b0e8..640f5a4fd6 100644 --- a/src/net/cgo_stub.go +++ b/src/net/cgo_stub.go @@ -31,7 +31,7 @@ func cgoLookupIP(ctx context.Context, network, name string) (addrs []IPAddr, err panic("cgo stub: cgo not available") } -func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error, completed bool) { +func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error) { panic("cgo stub: cgo not available") } diff --git a/src/net/cgo_unix.go b/src/net/cgo_unix.go index 1e170dbc0a..51efee6f87 100644 --- a/src/net/cgo_unix.go +++ b/src/net/cgo_unix.go @@ -297,16 +297,16 @@ func cgoSockaddr(ip IP, zone string) (*_C_struct_sockaddr, _C_socklen_t) { return nil, 0 } -func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error, completed bool) { +func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error) { resources, err := resSearch(ctx, name, int(dnsmessage.TypeCNAME), int(dnsmessage.ClassINET)) if err != nil { - return + return "", err } cname, err = parseCNAMEFromResources(resources) if err != nil { - return "", err, false + return "", err } - return cname, nil, true + return cname, nil } // resSearch will make a call to the 'res_nsearch' routine in the C library diff --git a/src/net/cgo_unix_test.go b/src/net/cgo_unix_test.go index d8233dfaf2..9aaeccc5f0 100644 --- a/src/net/cgo_unix_test.go +++ b/src/net/cgo_unix_test.go @@ -8,6 +8,7 @@ package net import ( "context" + "internal/testenv" "testing" ) @@ -67,3 +68,12 @@ func TestCgoLookupPTRWithCancel(t *testing.T) { t.Error(err) } } + +func TestCgoLookupCNAME(t *testing.T) { + mustHaveExternalNetwork(t) + testenv.SkipFlakyNet(t) + defer dnsWaitGroup.Wait() + if _, err := cgoLookupCNAME(t.Context(), "www.iana.org."); err != nil { + t.Error(err) + } +} diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go index 7416cb01f8..86108939cd 100644 --- a/src/net/lookup_unix.go +++ b/src/net/lookup_unix.go @@ -87,8 +87,8 @@ func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int func (r *Resolver) lookupCNAME(ctx context.Context, name string) (string, error) { order, conf := systemConf().hostLookupOrder(r, name) if order == hostLookupCgo { - if cname, err, ok := cgoLookupCNAME(ctx, name); ok { - return cname, err + if cname, err := cgoLookupCNAME(ctx, name); err == nil { + return cname, nil } } return r.goLookupCNAME(ctx, name, order, conf) |
