github.com/eagleql/xray-core@v1.4.4/transport/internet/sockopt_darwin.go (about)

     1  package internet
     2  
     3  import (
     4  	"syscall"
     5  )
     6  
     7  const (
     8  	// TCP_FASTOPEN is the socket option on darwin for TCP fast open.
     9  	TCP_FASTOPEN = 0x105
    10  	// TCP_FASTOPEN_SERVER is the value to enable TCP fast open on darwin for server connections.
    11  	TCP_FASTOPEN_SERVER = 0x01
    12  	// TCP_FASTOPEN_CLIENT is the value to enable TCP fast open on darwin for client connections.
    13  	TCP_FASTOPEN_CLIENT = 0x02
    14  )
    15  
    16  func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
    17  	if isTCPSocket(network) {
    18  		tfo := config.ParseTFOValue()
    19  		if tfo > 0 {
    20  			tfo = TCP_FASTOPEN_CLIENT
    21  		}
    22  		if tfo >= 0 {
    23  			if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
    24  				return err
    25  			}
    26  		}
    27  	}
    28  
    29  	return nil
    30  }
    31  
    32  func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
    33  	if isTCPSocket(network) {
    34  		tfo := config.ParseTFOValue()
    35  		if tfo > 0 {
    36  			tfo = TCP_FASTOPEN_SERVER
    37  		}
    38  		if tfo >= 0 {
    39  			if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
    40  				return err
    41  			}
    42  		}
    43  	}
    44  
    45  	return nil
    46  }
    47  
    48  func bindAddr(fd uintptr, address []byte, port uint32) error {
    49  	return nil
    50  }
    51  
    52  func setReuseAddr(fd uintptr) error {
    53  	return nil
    54  }
    55  
    56  func setReusePort(fd uintptr) error {
    57  	return nil
    58  }