sock_unsupported.go

 1//go:build (!linux && !darwin && !windows) || tinygo
 2
 3package sysfs
 4
 5import (
 6	"net"
 7	"syscall"
 8
 9	"github.com/tetratelabs/wazero/experimental/sys"
10	experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
11	"github.com/tetratelabs/wazero/internal/fsapi"
12	socketapi "github.com/tetratelabs/wazero/internal/sock"
13)
14
15// MSG_PEEK is a filler value.
16const MSG_PEEK = 0x2
17
18func newTCPListenerFile(tl *net.TCPListener) socketapi.TCPSock {
19	return &unsupportedSockFile{}
20}
21
22type unsupportedSockFile struct {
23	baseSockFile
24}
25
26// Accept implements the same method as documented on socketapi.TCPSock
27func (f *unsupportedSockFile) Accept() (socketapi.TCPConn, sys.Errno) {
28	return nil, sys.ENOSYS
29}
30
31func _pollSock(conn syscall.Conn, flag fsapi.Pflag, timeoutMillis int32) (bool, sys.Errno) {
32	return false, sys.ENOTSUP
33}
34
35func setNonblockSocket(fd uintptr, enabled bool) sys.Errno {
36	return sys.ENOTSUP
37}
38
39func readSocket(fd uintptr, buf []byte) (int, sys.Errno) {
40	return -1, sys.ENOTSUP
41}
42
43func writeSocket(fd uintptr, buf []byte) (int, sys.Errno) {
44	return -1, sys.ENOTSUP
45}
46
47func recvfrom(fd uintptr, buf []byte, flags int32) (n int, errno sys.Errno) {
48	return -1, sys.ENOTSUP
49}
50
51// syscallConnControl extracts a syscall.RawConn from the given syscall.Conn and applies
52// the given fn to a file descriptor, returning an integer or a nonzero syscall.Errno on failure.
53//
54// syscallConnControl streamlines the pattern of extracting the syscall.Rawconn,
55// invoking its syscall.RawConn.Control method, then handling properly the errors that may occur
56// within fn or returned by syscall.RawConn.Control itself.
57func syscallConnControl(conn syscall.Conn, fn func(fd uintptr) (int, experimentalsys.Errno)) (n int, errno sys.Errno) {
58	return -1, sys.ENOTSUP
59}
60
61// Accept implements the same method as documented on socketapi.TCPSock
62func (f *tcpListenerFile) Accept() (socketapi.TCPConn, experimentalsys.Errno) {
63	return nil, experimentalsys.ENOSYS
64}
65
66// Shutdown implements the same method as documented on experimentalsys.Conn
67func (f *tcpConnFile) Shutdown(how int) experimentalsys.Errno {
68	// FIXME: can userland shutdown listeners?
69	var err error
70	switch how {
71	case socketapi.SHUT_RD:
72		err = f.tc.Close()
73	case socketapi.SHUT_WR:
74		err = f.tc.Close()
75	case socketapi.SHUT_RDWR:
76		return f.close()
77	default:
78		return experimentalsys.EINVAL
79	}
80	return experimentalsys.UnwrapOSError(err)
81}