Documentation ¶
Overview ¶
Package gpool implements a tcp connection pool to manage connection and use
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrClosed is error which pool has been closed but still been used ErrClosed = errors.New("pool has been closed") // ErrNil is error which pool is nil but has been used ErrNil = errors.New("pool is nil") )
Functions ¶
This section is empty.
Types ¶
type GConn ¶
GConn wrap net.Conn to borrow or return conn
func (*GConn) MarkUnusable ¶
func (g *GConn) MarkUnusable()
MarkUnusable marks the connection not usable any more, to let the pool close it instead of returning it to pool.
type Pool ¶
type Pool interface { // Get returns a new connection from pool. Get() (net.Conn, error) // Close close the pool and reclaim all the connections. Close() // Len get the length of the pool Len() int // Idle get the idle connection pool number Idle() int // BlockingGet will block until it gets an idle connection from pool. Context timeout can be passed with context // to wait for specific amount of time. If nil is passed, this will wait indefinitely until a connection is // available. BlockingGet(context.Context) (net.Conn, error) }
Pool is interface which all type of pool need to implement
type PoolConfig ¶
type PoolConfig struct { // InitCap of the connection pool InitCap int // Maxcap is max connection number of the pool MaxCap int // WaitTimeout is the timeout for waiting to borrow a connection WaitTimeout time.Duration // IdleTimeout is the timeout for a connection to be alive IdleTimeout time.Duration Factory func() (net.Conn, error) }
PoolConfig used for config the connection pool
Click to show internal directories.
Click to hide internal directories.