Documentation ¶
Overview ¶
Package tcplisten provides customizable TCP net.Listener with various performance-related options:
SO_REUSEPORT. This option allows linear scaling server performance on multi-CPU servers. See https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ for details.
TCP_DEFER_ACCEPT. This option expects the server reads from the accepted connection before writing to them.
TCP_FASTOPEN. See https://lwn.net/Articles/508865/ for details.
The package is derived from https://github.com/kavu/go_reuseport .
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMemListenerClosed = errors.New("MemListener is already closed: use of closed network connection")
var ( // ErrTimeout is returned from Read() or Write() on timeout. ErrTimeout = errors.New("timeout") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // ReusePort enables SO_REUSEPORT. ReusePort bool // DeferAccept enables TCP_DEFER_ACCEPT. DeferAccept bool // FastOpen enables TCP_FASTOPEN. FastOpen bool // Backlog is the maximum number of pending TCP connections the listener // may queue before passing them to Accept. // See man 2 listen for details. // // By default system-level backlog value is used. Backlog int }
Config provides options to enable on the returned listener.
func (*Config) NewListener ¶
NewListener returns TCP listener with options set in the Config.
The function may be called many times for creating distinct listeners with the given config.
Only tcp4 and tcp6 networks are supported.
type MemListener ¶
type MemListener struct {
// contains filtered or unexported fields
}
MemListener provides in-memory dialer<->net.Listener implementation.
It may be used either for fast in-process client<->server communications without network stack overhead or for client<->server tests.
func NewMemListener ¶
func NewMemListener() *MemListener
NewMemListener returns new in-memory dialer<->net.Listener.
func (*MemListener) Accept ¶
func (ln *MemListener) Accept() (net.Conn, error)
Accept implements net.Listener's Accept.
It is safe calling Accept from concurrently running goroutines.
Accept returns new connection per each Dial call.
func (*MemListener) Addr ¶
func (ln *MemListener) Addr() net.Addr
Addr implements net.Listener's Addr.
func (*MemListener) Close ¶
func (ln *MemListener) Close() error
Close implements net.Listener's Close.
type PipeConns ¶
type PipeConns struct {
// contains filtered or unexported fields
}
PipeConns provides bi-directional connection pipe, which use in-process memory as a transport.
PipeConns must be created by calling NewPipeConns.
PipeConns has the following additional features comparing to connections returned from net.Pipe():
- It is faster.
- It buffers Write calls, so there is no need to have concurrent goroutine calling Read in order to unblock each Write call.
- It supports read and write deadlines.
PipeConns is NOT safe for concurrent use by multiple goroutines!
func NewPipeConns ¶
func NewPipeConns() *PipeConns
NewPipeConns returns new bi-directional connection pipe.
PipeConns is NOT safe for concurrent use by multiple goroutines!