Documentation ¶
Overview ¶
Package tfo provides TCP Fast Open support for the net dialer and listener.
The dial functions have an additional buffer parameter, which specifies data in SYN. If the buffer is empty, TFO is not used.
This package supports Linux, Windows, macOS, and FreeBSD. On unsupported platforms, ErrPlatformUnsupported is returned.
FreeBSD code is completely untested. Use at your own risk. Feedback is welcome.
Index ¶
- Constants
- func Dial(network, address string, b []byte) (net.Conn, error)
- func DialTCP(network string, laddr, raddr *net.TCPAddr, b []byte) (*net.TCPConn, error)
- func DialTimeout(network, address string, timeout time.Duration, b []byte) (net.Conn, error)
- func Listen(network, address string) (net.Listener, error)
- func ListenContext(ctx context.Context, network, address string) (net.Listener, error)
- func ListenTCP(network string, laddr *net.TCPAddr) (*net.TCPListener, error)
- func SetTFODialer(fd uintptr) error
- func SetTFOListener(fd uintptr) error
- func SetTFOListenerWithBacklog(fd uintptr, backlog int) error
- type Dialer
- type ListenConfig
- type PlatformUnsupportedError
Constants ¶
const TCPFastopenQueueLength = 4096
TCPFastopenQueueLength is the maximum number of total pending TFO connection requests, see https://datatracker.ietf.org/doc/html/rfc7413#section-5.1 for why this limit exists. The current value is the default net.core.somaxconn on Linux.
Deprecated: This constant is no longer used in this module and will be removed in v3.
Variables ¶
This section is empty.
Functions ¶
func DialTCP ¶
DialTCP is like net.DialTCP but enables TFO whenever possible.
func DialTimeout ¶
DialTimeout is like net.DialTimeout but enables TFO whenever possible.
func Listen ¶
Listen is like net.Listen but enables TFO whenever possible.
func ListenContext ¶
ListenContext is like net.ListenContext but enables TFO whenever possible.
func ListenTCP ¶
ListenTCP is like net.ListenTCP but enables TFO whenever possible.
func SetTFODialer ¶
SetTFODialer enables TCP Fast Open on the dialer.
func SetTFOListener ¶
SetTFOListener enables TCP Fast Open on the listener. On platforms where a backlog argument is required, Go std's listen(2) backlog is used. To specify a custom backlog, use SetTFOListenerWithBacklog.
func SetTFOListenerWithBacklog ¶ added in v2.2.0
SetTFOListenerWithBacklog enables TCP Fast Open on the listener with the given backlog. If the backlog is 0, Go std's listen(2) backlog is used. If the platform does not support custom backlog values, the given backlog is ignored.
Types ¶
type Dialer ¶
type Dialer struct { net.Dialer // DisableTFO controls whether TCP Fast Open is disabled when the dial methods are called. // TFO is enabled by default. // Set to true to disable TFO and it will behave exactly the same as [net.Dialer]. DisableTFO bool // Fallback controls whether to proceed without TFO when TFO is enabled but not supported // on the system. // On Linux this also controls whether the sendto(MSG_FASTOPEN) fallback path is tried // before giving up on TFO. Fallback bool }
Dialer wraps net.Dialer with an additional option that allows you to disable TFO.
func (*Dialer) Dial ¶
Dial is like net.Dialer.Dial but enables TFO whenever possible, unless [Dialer.DisableTFO] is set to true.
type ListenConfig ¶
type ListenConfig struct { net.ListenConfig // Backlog specifies the maximum number of pending TFO connections on supported platforms. // If the value is 0, Go std's listen(2) backlog is used. // If the value is negative, TFO is disabled. Backlog int // DisableTFO controls whether TCP Fast Open is disabled when the Listen method is called. // TFO is enabled by default, unless [ListenConfig.Backlog] is negative. // Set to true to disable TFO and it will behave exactly the same as [net.ListenConfig]. DisableTFO bool // Fallback controls whether to proceed without TFO when TFO is enabled but not supported // on the system. Fallback bool }
ListenConfig wraps net.ListenConfig with TFO-related options.
func (*ListenConfig) Listen ¶
Listen is like net.ListenConfig.Listen but enables TFO whenever possible, unless [ListenConfig.Backlog] is negative or [ListenConfig.DisableTFO] is set to true.
type PlatformUnsupportedError ¶ added in v2.2.0
type PlatformUnsupportedError struct{}
PlatformUnsupportedError is returned when tfo-go does not support TCP Fast Open on the current platform.
var (
ErrPlatformUnsupported PlatformUnsupportedError
)
func (PlatformUnsupportedError) Error ¶ added in v2.2.0
func (PlatformUnsupportedError) Error() string
func (PlatformUnsupportedError) Is ¶ added in v2.2.0
func (PlatformUnsupportedError) Is(target error) bool