net: add UDP listen, resolver, DNSError, and TCP listener APIs for wasm (#63)

* net: add UDP listen, resolver, DNSError, and TCP listener APIs for wasm

TinyGo's net package was missing several symbols that upstream Go's
js/wasm net declares, blocking builds that pull pion/transport, pion/dtls,
and similar (via netbird's WASM client). Add them, backed by the existing
netdev abstraction so they compile for all targets and no-op cleanly under
nopNetdev (matching Go's js runtime behavior):

- DNSError type (dnserror.go), copied from Go 1.26.2.
- Resolver + DefaultResolver with LookupHost/LookupIP/LookupIPAddr/
  LookupNetIP/LookupPort; LookupHost/LookupIP package funcs; Dialer.Resolver
  field for API compatibility.
- UDPConn: ListenUDP, ReadFromUDP(AddrPort), WriteToUDP(AddrPort),
  SetReadBuffer, SetWriteBuffer.
- TCPConn: CloseRead, SetNoDelay, SetReadBuffer, SetWriteBuffer,
  ReadFrom(io.Reader).
- TCPListener: ListenTCP, AcceptTCP, SetDeadline; ListenPacket package func.
- Interface: Addrs, MulticastAddrs stubs.

* more complete PR for adding more net support (#64)

* format unixsock
This commit is contained in:
Pat Whittingslow
2026-07-06 15:24:35 -03:00
committed by GitHub
parent 1026408a38
commit d5da3ddeef
12 changed files with 770 additions and 1 deletions
+26
View File
@@ -87,6 +87,13 @@ type Dialer struct {
// If KeepAliveConfig.Enable is false and KeepAlive is negative,
// keep-alive probes are disabled.
KeepAliveConfig KeepAliveConfig
// Resolver optionally specifies an alternate resolver to use.
//
// TINYGO: present for API compatibility; DialContext resolves via the
// netdev-backed ResolveTCPAddr/ResolveUDPAddr and does not consult this
// field.
Resolver *Resolver
}
// Dial connects to the address on the named network.
@@ -281,3 +288,22 @@ func Listen(network, address string) (Listener, error) {
return listenTCP(laddr)
}
// ListenPacket announces on the local network address.
//
// TINYGO: only UDP networks are supported, backed by ListenUDP; the
// returned PacketConn is a *UDPConn.
func ListenPacket(network, address string) (PacketConn, error) {
switch network {
case "udp", "udp4":
default:
return nil, fmt.Errorf("Network %s not supported", network)
}
laddr, err := ResolveUDPAddr(network, address)
if err != nil {
return nil, err
}
return ListenUDP(network, laddr)
}