mirror of
https://github.com/golang/go
synced 2024-11-18 04:04:49 -07: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:
parent
b45cb0ce86
commit
a5b10be471
@ -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
|
// resSearch will make a call to the 'res_nsearch' routine in the C library
|
||||||
// and parse the output as a slice of DNS resources.
|
// and parse the output as a slice of DNS resources.
|
||||||
func resSearch(ctx context.Context, hostname string, rtype, class int) ([]dnsmessage.Resource, error) {
|
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()
|
acquireThread()
|
||||||
defer releaseThread()
|
defer releaseThread()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user