//go:build (linux || darwin || windows) && !tinygo

package sysfs

import (
	
	

	experimentalsys 
	
	socketapi 
)

// Accept implements the same method as documented on socketapi.TCPSock
func ( *tcpListenerFile) () (socketapi.TCPConn, experimentalsys.Errno) {
	// Ensure we have an incoming connection, otherwise return immediately.
	if .nonblock {
		if ,  := _pollSock(.tl, fsapi.POLLIN, 0); ! ||  != 0 {
			return nil, experimentalsys.EAGAIN
		}
	}

	// Accept normally blocks goroutines, but we
	// made sure that we have an incoming connection,
	// so we should be safe.
	if ,  := .tl.Accept();  != nil {
		return nil, experimentalsys.UnwrapOSError()
	} else {
		return newTcpConn(.(*net.TCPConn)), 0
	}
}

// SetNonblock implements the same method as documented on fsapi.File
func ( *tcpListenerFile) ( bool) ( experimentalsys.Errno) {
	.nonblock = 
	_,  = syscallConnControl(.tl, func( uintptr) (int, experimentalsys.Errno) {
		return 0, setNonblockSocket(, )
	})
	return
}

// Shutdown implements the same method as documented on experimentalsys.Conn
func ( *tcpConnFile) ( int) experimentalsys.Errno {
	// FIXME: can userland shutdown listeners?
	var  error
	switch  {
	case socketapi.SHUT_RD:
		 = .tc.CloseRead()
	case socketapi.SHUT_WR:
		 = .tc.CloseWrite()
	case socketapi.SHUT_RDWR:
		return .close()
	default:
		return experimentalsys.EINVAL
	}
	return experimentalsys.UnwrapOSError()
}

// syscallConnControl extracts a syscall.RawConn from the given syscall.Conn and applies
// the given fn to a file descriptor, returning an integer or a nonzero syscall.Errno on failure.
//
// syscallConnControl streamlines the pattern of extracting the syscall.Rawconn,
// invoking its syscall.RawConn.Control method, then handling properly the errors that may occur
// within fn or returned by syscall.RawConn.Control itself.
func syscallConnControl( syscall.Conn,  func( uintptr) (int, experimentalsys.Errno)) ( int,  experimentalsys.Errno) {
	,  := .SyscallConn()
	if  != nil {
		return 0, experimentalsys.UnwrapOSError()
	}
	// Prioritize the inner errno over Control
	if  := .Control(func( uintptr) {
		,  = ()
	});  == 0 {
		 = experimentalsys.UnwrapOSError()
	}
	return
}