mirror of
https://github.com/tinygo-org/net.git
synced 2026-08-15 08:53:40 +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:
+32
@@ -6,6 +6,11 @@
|
||||
|
||||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BUG(mikio): On JS, WASIP1 and Plan 9, methods and functions related
|
||||
// to UnixConn and UnixListener are not implemented.
|
||||
|
||||
@@ -44,6 +49,33 @@ func (a *UnixAddr) opAddr() Addr {
|
||||
return a
|
||||
}
|
||||
|
||||
// UnixConn is an implementation of the Conn interface for connections to Unix
|
||||
// domain sockets.
|
||||
//
|
||||
// TINYGO: Unix sockets are not implemented (the browser has no filesystem
|
||||
// sockets). This type exists only to satisfy references and type assertions
|
||||
// such as those in github.com/gliderlabs/ssh agent forwarding; all methods
|
||||
// return an error. The corresponding code paths are never reached at runtime in
|
||||
// the wasm build.
|
||||
type UnixConn struct {
|
||||
fd int
|
||||
laddr *UnixAddr
|
||||
raddr *UnixAddr
|
||||
}
|
||||
|
||||
var errUnixNotImplemented = errors.New("net: Unix sockets not implemented")
|
||||
|
||||
func (c *UnixConn) Read(b []byte) (int, error) { return 0, errUnixNotImplemented }
|
||||
func (c *UnixConn) Write(b []byte) (int, error) { return 0, errUnixNotImplemented }
|
||||
func (c *UnixConn) Close() error { return errUnixNotImplemented }
|
||||
func (c *UnixConn) CloseRead() error { return errUnixNotImplemented }
|
||||
func (c *UnixConn) CloseWrite() error { return errUnixNotImplemented }
|
||||
func (c *UnixConn) LocalAddr() Addr { return c.laddr }
|
||||
func (c *UnixConn) RemoteAddr() Addr { return c.raddr }
|
||||
func (c *UnixConn) SetDeadline(t time.Time) error { return errUnixNotImplemented }
|
||||
func (c *UnixConn) SetReadDeadline(t time.Time) error { return errUnixNotImplemented }
|
||||
func (c *UnixConn) SetWriteDeadline(t time.Time) error { return errUnixNotImplemented }
|
||||
|
||||
// ResolveUnixAddr returns an address of Unix domain socket end point.
|
||||
//
|
||||
// The network must be a Unix network name.
|
||||
|
||||
Reference in New Issue
Block a user