1
0
mirror of https://github.com/golang/go synced 2024-09-30 07:28:36 -06:00

net: support context cancellation in resSearch

As with all the stuff that call cgo from net package.

Change-Id: I7c42ae44a1d47f4f949b203682217498fcdba92a
GitHub-Last-Rev: 70406493bb
GitHub-Pull-Request: golang/go#57043
Reviewed-on: https://go-review.googlesource.com/c/go/+/454697
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2022-12-03 08:14:33 +00:00 committed by Gopher Robot
parent b45cb0ce86
commit a5b10be471

View File

@ -331,6 +331,33 @@ func cgoLookupCNAME(ctx context.Context, name string) (cname string, err error,
// resSearch will make a call to the 'res_nsearch' routine in the C library
// and parse the output as a slice of DNS resources.
func resSearch(ctx context.Context, hostname string, rtype, class int) ([]dnsmessage.Resource, error) {
if ctx.Done() == nil {
return cgoResSearch(hostname, rtype, class)
}
type result struct {
res []dnsmessage.Resource
err error
}
res := make(chan result, 1)
go func() {
r, err := cgoResSearch(hostname, rtype, class)
res <- result{
res: r,
err: err,
}
}()
select {
case res := <-res:
return res.res, res.err
case <-ctx.Done():
return nil, mapErr(ctx.Err())
}
}
func cgoResSearch(hostname string, rtype, class int) ([]dnsmessage.Resource, error) {
acquireThread()
defer releaseThread()