1//go:build (linux || darwin) && !tinygo
2
3package sysfs
4
5import (
6 "net"
7 "syscall"
8
9 "github.com/tetratelabs/wazero/experimental/sys"
10 "github.com/tetratelabs/wazero/internal/fsapi"
11 socketapi "github.com/tetratelabs/wazero/internal/sock"
12)
13
14// MSG_PEEK is the constant syscall.MSG_PEEK
15const MSG_PEEK = syscall.MSG_PEEK
16
17func newTCPListenerFile(tl *net.TCPListener) socketapi.TCPSock {
18 return newDefaultTCPListenerFile(tl)
19}
20
21func _pollSock(conn syscall.Conn, flag fsapi.Pflag, timeoutMillis int32) (bool, sys.Errno) {
22 n, errno := syscallConnControl(conn, func(fd uintptr) (int, sys.Errno) {
23 if ready, errno := poll(fd, fsapi.POLLIN, 0); !ready || errno != 0 {
24 return -1, errno
25 } else {
26 return 0, errno
27 }
28 })
29 return n >= 0, errno
30}
31
32func setNonblockSocket(fd uintptr, enabled bool) sys.Errno {
33 return sys.UnwrapOSError(setNonblock(fd, enabled))
34}
35
36func readSocket(fd uintptr, buf []byte) (int, sys.Errno) {
37 n, err := syscall.Read(int(fd), buf)
38 return n, sys.UnwrapOSError(err)
39}
40
41func writeSocket(fd uintptr, buf []byte) (int, sys.Errno) {
42 n, err := syscall.Write(int(fd), buf)
43 return n, sys.UnwrapOSError(err)
44}
45
46func recvfrom(fd uintptr, buf []byte, flags int32) (n int, errno sys.Errno) {
47 n, _, err := syscall.Recvfrom(int(fd), buf, int(flags))
48 return n, sys.UnwrapOSError(err)
49}