package sysfs
import (
"net"
"syscall"
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/fsapi"
socketapi "github.com/tetratelabs/wazero/internal/sock"
)
func (f *tcpListenerFile ) Accept () (socketapi .TCPConn , experimentalsys .Errno ) {
if f .nonblock {
if ready , errno := _pollSock (f .tl , fsapi .POLLIN , 0 ); !ready || errno != 0 {
return nil , experimentalsys .EAGAIN
}
}
if conn , err := f .tl .Accept (); err != nil {
return nil , experimentalsys .UnwrapOSError (err )
} else {
return newTcpConn (conn .(*net .TCPConn )), 0
}
}
func (f *tcpListenerFile ) SetNonblock (enabled bool ) (errno experimentalsys .Errno ) {
f .nonblock = enabled
_, errno = syscallConnControl (f .tl , func (fd uintptr ) (int , experimentalsys .Errno ) {
return 0 , setNonblockSocket (fd , enabled )
})
return
}
func (f *tcpConnFile ) Shutdown (how int ) experimentalsys .Errno {
var err error
switch how {
case socketapi .SHUT_RD :
err = f .tc .CloseRead ()
case socketapi .SHUT_WR :
err = f .tc .CloseWrite ()
case socketapi .SHUT_RDWR :
return f .close ()
default :
return experimentalsys .EINVAL
}
return experimentalsys .UnwrapOSError (err )
}
func syscallConnControl(conn syscall .Conn , fn func (fd uintptr ) (int , experimentalsys .Errno )) (n int , errno experimentalsys .Errno ) {
syscallConn , err := conn .SyscallConn ()
if err != nil {
return 0 , experimentalsys .UnwrapOSError (err )
}
if controlErr := syscallConn .Control (func (fd uintptr ) {
n , errno = fn (fd )
}); errno == 0 {
errno = experimentalsys .UnwrapOSError (controlErr )
}
return
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .