github.com/tetratelabs/wazero@v1.2.1/internal/sysfs/sock.go (about) 1 package sysfs 2 3 import ( 4 "net" 5 "os" 6 "syscall" 7 8 "github.com/tetratelabs/wazero/internal/fsapi" 9 socketapi "github.com/tetratelabs/wazero/internal/sock" 10 ) 11 12 // NewTCPListenerFile creates a socketapi.TCPSock for a given *net.TCPListener. 13 func NewTCPListenerFile(tl *net.TCPListener) socketapi.TCPSock { 14 return newTCPListenerFile(tl) 15 } 16 17 // baseSockFile implements base behavior for all TCPSock, TCPConn files, 18 // regardless the platform. 19 type baseSockFile struct { 20 fsapi.UnimplementedFile 21 } 22 23 var _ fsapi.File = (*baseSockFile)(nil) 24 25 // IsDir implements the same method as documented on File.IsDir 26 func (*baseSockFile) IsDir() (bool, syscall.Errno) { 27 // We need to override this method because WASI-libc prestats the FD 28 // and the default impl returns ENOSYS otherwise. 29 return false, 0 30 } 31 32 // Stat implements the same method as documented on File.Stat 33 func (f *baseSockFile) Stat() (fs fsapi.Stat_t, errno syscall.Errno) { 34 // The mode is not really important, but it should be neither a regular file nor a directory. 35 fs.Mode = os.ModeIrregular 36 return 37 }