github.com/database64128/tfo-go/v2@v2.2.0/sockopt_linux.go (about)

     1  package tfo
     2  
     3  import (
     4  	_ "unsafe"
     5  
     6  	"golang.org/x/sys/unix"
     7  )
     8  
     9  // TCPFastopenQueueLength is the maximum number of total pending TFO connection requests,
    10  // see https://datatracker.ietf.org/doc/html/rfc7413#section-5.1 for why this limit exists.
    11  // The current value is the default net.core.somaxconn on Linux.
    12  //
    13  // Deprecated: This constant is no longer used in this module and will be removed in v3.
    14  const TCPFastopenQueueLength = 4096
    15  
    16  func setTFOListener(fd uintptr) error {
    17  	return setTFOListenerWithBacklog(fd, 0)
    18  }
    19  
    20  func setTFOListenerWithBacklog(fd uintptr, backlog int) error {
    21  	if backlog == 0 {
    22  		backlog = listenerBacklog()
    23  	}
    24  	return setTFO(int(fd), backlog)
    25  }
    26  
    27  // listenerBacklog is linked from src/net/net.go
    28  //
    29  //go:linkname listenerBacklog net.listenerBacklog
    30  func listenerBacklog() int
    31  
    32  func setTFODialer(fd uintptr) error {
    33  	return unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_FASTOPEN_CONNECT, 1)
    34  }