mirror of https://github.com/golang/go.git
net: enable pure Go resolver for wasip1
Top-level functions in the net package that only read files, for example LookupPort(...), or LookupIP(host) where host resides in /etc/hosts, now work on wasip1. If the application has the ability to create sockets (for example, when using a sockets extension to WASI preview 1), it's now possible to do name resolution by passing a custom Dial function to a Resolver instance. Change-Id: I923886f67e336820bc89f09ea1855387c8dac61a Reviewed-on: https://go-review.googlesource.com/c/go/+/500579 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Randy Reddig <ydnar@shaderlab.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
parent
1e97c51536
commit
18e17e2cb1
|
|
@ -4,11 +4,12 @@
|
||||||
|
|
||||||
// This file holds stub versions of the cgo functions called on Unix systems.
|
// This file holds stub versions of the cgo functions called on Unix systems.
|
||||||
// We build this file if using the netgo build tag, or if cgo is not
|
// We build this file if using the netgo build tag, or if cgo is not
|
||||||
// enabled and we are using a Unix system other than Darwin.
|
// enabled and we are using a Unix system other than Darwin, or if it's
|
||||||
|
// wasip1 where cgo is never available.
|
||||||
// Darwin is exempted because it always provides the cgo routines,
|
// Darwin is exempted because it always provides the cgo routines,
|
||||||
// in cgo_unix_syscall.go.
|
// in cgo_unix_syscall.go.
|
||||||
|
|
||||||
//go:build netgo || (!cgo && unix && !darwin)
|
//go:build netgo || (!cgo && unix && !darwin) || wasip1
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !js && !wasip1
|
//go:build !js
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !js && !wasip1
|
//go:build !js
|
||||||
|
|
||||||
// DNS client: see RFC 1035.
|
// DNS client: see RFC 1035.
|
||||||
// Has to be linked into package net for Dial.
|
// Has to be linked into package net for Dial.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !js && !wasip1 && !windows
|
//go:build !js && !windows
|
||||||
|
|
||||||
// Read system DNS config from /etc/resolv.conf
|
// Read system DNS config from /etc/resolv.conf
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (js && wasm) || wasip1
|
//go:build js && wasm
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build unix
|
//go:build unix || wasip1
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/dns/dnsmessage"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var listenersMu sync.Mutex
|
var listenersMu sync.Mutex
|
||||||
|
|
@ -406,7 +404,3 @@ func (fd *fakeNetFD) writeMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int,
|
||||||
func (fd *fakeNetFD) dup() (f *os.File, err error) {
|
func (fd *fakeNetFD) dup() (f *os.File, err error) {
|
||||||
return nil, syscall.ENOSYS
|
return nil, syscall.ENOSYS
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver) lookup(ctx context.Context, name string, qtype dnsmessage.Type, conf *dnsConfig) (dnsmessage.Parser, string, error) {
|
|
||||||
panic("unreachable")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,12 @@
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
import "internal/poll"
|
import (
|
||||||
|
"context"
|
||||||
|
"internal/poll"
|
||||||
|
|
||||||
|
"golang.org/x/net/dns/dnsmessage"
|
||||||
|
)
|
||||||
|
|
||||||
// Network file descriptor.
|
// Network file descriptor.
|
||||||
type netFD struct {
|
type netFD struct {
|
||||||
|
|
@ -25,3 +30,7 @@ type netFD struct {
|
||||||
pfd poll.FD
|
pfd poll.FD
|
||||||
isConnected bool // handshake completed or use of association with peer
|
isConnected bool // handshake completed or use of association with peer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Resolver) lookup(ctx context.Context, name string, qtype dnsmessage.Type, conf *dnsConfig) (dnsmessage.Parser, string, error) {
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue