Documentation
¶
Overview ¶
Package vconnpool 提供高性能、可复用的网络连接池
Index ¶
- Variables
- func ResolveAddr(network, address string) (net.Addr, error)
- type Addr
- type Conn
- type Dialer
- type Pool
- func (p *Pool) Add(conn net.Conn) error
- func (p *Pool) Close() error
- func (p *Pool) CloseIdleConnection(addr net.Addr)
- func (p *Pool) CloseIdleConnections()
- func (p *Pool) Dial(network, address string) (Conn, error)
- func (p *Pool) DialContext(ctx context.Context, network, address string) (Conn, error)
- func (p *Pool) Get(addr net.Addr) (conn net.Conn, err error)
- func (p *Pool) Num() int
- func (p *Pool) NumConn(addr net.Addr) int
- func (p *Pool) NumIdle(addr net.Addr) int
- func (p *Pool) Put(conn net.Conn, addr net.Addr) error
- func (p *Pool) WaitConnIdleGeq(addr net.Addr, l int) <-chan bool
- func (p *Pool) WaitConnIdleLeq(addr net.Addr, l int) <-chan bool
- func (p *Pool) WaitConnNumGeq(addr net.Addr, l int) <-chan bool
- func (p *Pool) WaitConnNumLeq(addr net.Addr, l int) <-chan bool
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrConnClose = errors.New("vconnpool: the connection is closed") ErrConnPoolClosed = errors.New("vconnpool: the connection pool has been closed") ErrConnRAWRead = errors.New("vconnpool: the original connection cannot be read repeatedly or is closed") // 错误信息更明确 ErrConnNotAvailable = errors.New("vconnpool: no available connection in the pool") ErrConnPoolMax = errors.New("vconnpool: the number of connections has reached the maximum limit") ErrConnIdleMax = errors.New("vconnpool: the number of idle connections has reached the maximum") ErrConnAlreadyExists = errors.New("vconnpool: the connection already exists in the idle pool") )
View Source
var PriorityContextKey = &contextKey{"priority"}
PriorityContextKey 上下文键,用于标记是否优先创建新连接(不使用连接池)
Functions ¶
Types ¶
type Dialer ¶
type Dialer interface {
Dial(network, address string) (net.Conn, error)
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer 接口定义
type Pool ¶ added in v3.0.2
type Pool struct {
Dialer Dialer
ResolveAddr func(network, address string) (net.Addr, error)
IdleConn int
IdleTimeout time.Duration
MaxConn int
// contains filtered or unexported fields
}
func (*Pool) CloseIdleConnection ¶ added in v3.0.3
CloseIdleConnection 关闭指定地址的空闲连接
func (*Pool) CloseIdleConnections ¶ added in v3.0.2
func (p *Pool) CloseIdleConnections()
CloseIdleConnections 关闭所有地址的空闲连接
func (*Pool) DialContext ¶ added in v3.0.2
func (*Pool) WaitConnIdleGeq ¶ added in v3.2.0
func (*Pool) WaitConnIdleLeq ¶ added in v3.2.0
func (*Pool) WaitConnNumGeq ¶ added in v3.2.0
Click to show internal directories.
Click to hide internal directories.