mirror of
https://github.com/tinygo-org/net.git
synced 2026-07-26 08:18:39 +00:00
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:
+47
@@ -0,0 +1,47 @@
|
||||
// TINYGO: The following is copied and modified from Go 1.26.2 official implementation.
|
||||
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package net
|
||||
|
||||
// DNSError represents a DNS lookup error.
|
||||
type DNSError struct {
|
||||
UnwrapErr error // error returned by the [DNSError.Unwrap] method, might be nil
|
||||
Err string // description of the error
|
||||
Name string // name looked for
|
||||
Server string // server used
|
||||
IsTimeout bool // if true, timed out; not all timeouts set this
|
||||
IsTemporary bool // if true, error is temporary; not all errors set this
|
||||
|
||||
// IsNotFound is set to true when the requested name does not
|
||||
// contain any records of the requested type (data not found),
|
||||
// or the name itself was not found (NXDOMAIN).
|
||||
IsNotFound bool
|
||||
}
|
||||
|
||||
// Unwrap returns e.UnwrapErr.
|
||||
func (e *DNSError) Unwrap() error { return e.UnwrapErr }
|
||||
|
||||
func (e *DNSError) Error() string {
|
||||
if e == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
s := "lookup " + e.Name
|
||||
if e.Server != "" {
|
||||
s += " on " + e.Server
|
||||
}
|
||||
s += ": " + e.Err
|
||||
return s
|
||||
}
|
||||
|
||||
// Timeout reports whether the DNS lookup is known to have timed out.
|
||||
// This is not always known; a DNS lookup may fail due to a timeout
|
||||
// and return a [DNSError] for which Timeout returns false.
|
||||
func (e *DNSError) Timeout() bool { return e.IsTimeout }
|
||||
|
||||
// Temporary reports whether the DNS error is known to be temporary.
|
||||
// This is not always known; a DNS lookup may fail due to a temporary
|
||||
// error and return a [DNSError] for which Temporary returns false.
|
||||
func (e *DNSError) Temporary() bool { return e.IsTimeout || e.IsTemporary }
|
||||
Reference in New Issue
Block a user