stub out more types/funcs to compile against golang.org/x/net/internal/socket (#17)

* stub out more types/funcs to compile against golang.org/x/net/internal/socket

These are changes need to compile github.com/domainr/dnsr/ with TinyGo. See issue tinygo-org/net#14.

These change are mostly to fix missing symbols in src/net. Missing types and functions are cut-and-pasted from go1.21.4. Functions are stubbed out returning errors.New("not implemented").

DNRS is compiled by running tinygo test:

   sfeldma@nuc:~/work/dnsr$ tinygo test -target=wasi

With this patch, and a corresponding patch for tinygo/ to fixup crypto/tls, you should get a clean compile.
This commit is contained in:
Scott Feldman
2023-12-17 06:29:45 -08:00
committed by GitHub
parent 4f0d9658ab
commit 4bc93e2fd8
10 changed files with 410 additions and 1 deletions
+28
View File
@@ -13,6 +13,7 @@ import (
"io"
"net/netip"
"strconv"
"syscall"
"time"
)
@@ -178,6 +179,12 @@ func DialTCP(network string, laddr, raddr *TCPAddr) (*TCPConn, error) {
// TINYGO: Use netdev for Conn methods: Read = Recv, Write = Send, etc.
// SyscallConn returns a raw network connection.
// This implements the syscall.Conn interface.
func (c *TCPConn) SyscallConn() (syscall.RawConn, error) {
return nil, errors.New("SyscallConn not implemented")
}
func (c *TCPConn) Read(b []byte) (int, error) {
n, err := netdev.Recv(c.fd, b, 0, c.readDeadline)
// Turn the -1 socket error into 0 and let err speak for error
@@ -220,10 +227,31 @@ func (c *TCPConn) SetDeadline(t time.Time) error {
return nil
}
// SetLinger sets the behavior of Close on a connection which still
// has data waiting to be sent or to be acknowledged.
//
// If sec < 0 (the default), the operating system finishes sending the
// data in the background.
//
// If sec == 0, the operating system discards any unsent or
// unacknowledged data.
//
// If sec > 0, the data is sent in the background as with sec < 0.
// On some operating systems including Linux, this may cause Close to block
// until all data has been sent or discarded.
// On some operating systems after sec seconds have elapsed any remaining
// unsent data may be discarded.
func (c *TCPConn) SetLinger(sec int) error {
return netdev.SetSockOpt(c.fd, _SOL_SOCKET, _SO_LINGER, sec)
}
// SetKeepAlive sets whether the operating system should send
// keep-alive messages on the connection.
func (c *TCPConn) SetKeepAlive(keepalive bool) error {
return netdev.SetSockOpt(c.fd, _SOL_SOCKET, _SO_KEEPALIVE, keepalive)
}
// SetKeepAlivePeriod sets period between keep-alives.
func (c *TCPConn) SetKeepAlivePeriod(d time.Duration) error {
// Units are 1/2 seconds
return netdev.SetSockOpt(c.fd, _SOL_TCP, _TCP_KEEPINTVL, 2*d.Seconds())