gncp

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnPool

type ConnPool interface {
	Get() (net.Conn, error)
	GetWithTimeout(timeout time.Duration) (net.Conn, error)
	Close() error
	Remove(conn net.Conn) error
}

type CpConn

type CpConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*CpConn) Close

func (conn *CpConn) Close() error

Close will push connection back to connection pool. It will not close the real connection.

func (*CpConn) Destroy

func (conn *CpConn) Destroy() error

Destroy will close connection and release connection from connection pool.

type GncpPool

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

GncpPool implements ConnPool interface. Use channel buffer connections.

func NewPool

func NewPool(minConn, maxConn int, connCreator func() (net.Conn, error)) (*GncpPool, error)

NewPool return new ConnPool. It base on channel. It will init minConn connections in channel first. When Get()/GetWithTimeout called, if channel still has connection it will get connection from channel. Otherwise GncpPool check number of connection which had already created as the number are less than maxConn, it use connCreator function to create new connection.

func (*GncpPool) Close

func (p *GncpPool) Close() error

Close close the connection pool. When close the connection pool it also close all connection already in connection pool. If connection not put back in connection it will not close. But it will close when it put back.

func (*GncpPool) Get

func (p *GncpPool) Get() (net.Conn, error)

Get get connection from connection pool. If connection poll is empty and alreay created connection number less than Max number of connection it will create new one. Otherwise it wil wait someone put connection back.

func (*GncpPool) GetMaxConns

func (p *GncpPool) GetMaxConns() int

GetMaxConns returns the maximum number of connections configured

func (*GncpPool) GetWithContext

func (p *GncpPool) GetWithContext(ctx context.Context) (net.Conn, error)

func (*GncpPool) GetWithTimeout

func (p *GncpPool) GetWithTimeout(timeout time.Duration) (net.Conn, error)

GetWithTimeout can let you get connection wait for a time duration. If cannot get connection in this time. It will return TimeOutError.

func (*GncpPool) Put

func (p *GncpPool) Put(conn net.Conn) error

Put can put connection back in connection pool. If connection has been closed, the connection will be close too.

func (*GncpPool) Remove

func (p *GncpPool) Remove(conn net.Conn) error

Remove let connection not belong connection pool. And it will close connection.

Jump to

Keyboard shortcuts

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