github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/sysfs/sock.go (about) 1 package sysfs 2 3 import ( 4 "net" 5 "os" 6 7 experimentalsys "github.com/wasilibs/wazerox/experimental/sys" 8 socketapi "github.com/wasilibs/wazerox/internal/sock" 9 "github.com/wasilibs/wazerox/sys" 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 experimentalsys.UnimplementedFile 21 } 22 23 var _ experimentalsys.File = (*baseSockFile)(nil) 24 25 // IsDir implements the same method as documented on File.IsDir 26 func (*baseSockFile) IsDir() (bool, experimentalsys.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 sys.Stat_t, errno experimentalsys.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 }