netutil

package
v1.31.1-cluster Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2019 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnPool

type ConnPool struct {
	// contains filtered or unexported fields
}

ConnPool is a connection pool with ZSTD-compressed connections.

func NewConnPool

func NewConnPool(name, addr string, handshakeFunc handshake.Func, compressionLevel int) *ConnPool

NewConnPool creates a new connection pool for the given addr.

Name is used in exported metrics. handshakeFunc is used for handshaking after the connection establishing. The compression is disabled if compressionLevel <= 0.

func (*ConnPool) Addr

func (cp *ConnPool) Addr() string

Addr returns the address where connections are established.

func (*ConnPool) Get

func (cp *ConnPool) Get() (*handshake.BufferedConn, error)

Get returns free connection from the pool.

func (*ConnPool) Put

func (cp *ConnPool) Put(bc *handshake.BufferedConn)

Put puts bc back to the pool.

Do not put broken and closed connections to the pool!

type TCPDialer

type TCPDialer struct {
	// contains filtered or unexported fields
}

TCPDialer is used for dialing the addr passed to NewTCPDialer.

It also gathers various stats for dialed connections.

func NewTCPDialer

func NewTCPDialer(name, addr string) *TCPDialer

NewTCPDialer returns new dialer for dialing the given addr.

The name is used in metric tags for the returned dialer. The name must be unique among dialers.

func (*TCPDialer) Addr

func (d *TCPDialer) Addr() string

Addr returns the address the dialer dials to.

func (*TCPDialer) Dial

func (d *TCPDialer) Dial() (net.Conn, error)

Dial dials the addr passed to NewTCPDialer.

type TCPListener

type TCPListener struct {
	// ReadTimeout is timeout for each Read call on accepted conns.
	//
	// By default it isn't set.
	//
	// Set ReadTimeout before calling Accept the first time.
	ReadTimeout time.Duration

	// WriteTimeout is timeout for each Write call on accepted conns.
	//
	// By default it isn't set.
	//
	// Set WriteTimeout before calling Accept the first time.
	WriteTimeout time.Duration

	net.Listener
	// contains filtered or unexported fields
}

TCPListener listens for the addr passed to NewTCPListener.

It also gathers various stats for the accepted connections.

func NewTCPListener

func NewTCPListener(name, addr string) (*TCPListener, error)

NewTCPListener returns new TCP listener for the given addr.

name is used for exported metrics. Each listener in the program must have distinct name.

func (*TCPListener) Accept

func (ln *TCPListener) Accept() (net.Conn, error)

Accept accepts connections from the addr passed to NewTCPListener.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL