pool

package
v6.9.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("pg: database is closed")
View Source
var ErrPoolTimeout = errors.New("pg: connection pool timeout")

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Reader *bufio.Reader

	Columns [][]byte

	Writer *WriteBuffer

	InitedAt time.Time
	UsedAt   time.Time

	ProcessId int32
	SecretKey int32
	// contains filtered or unexported fields
}

func NewConn

func NewConn(netConn net.Conn) *Conn

func (*Conn) CheckHealth

func (cn *Conn) CheckHealth() error

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) FlushWriter

func (cn *Conn) FlushWriter() error

func (*Conn) NetConn

func (cn *Conn) NetConn() net.Conn

func (*Conn) NextId

func (cn *Conn) NextId() string

func (*Conn) ReadN

func (cn *Conn) ReadN(n int) ([]byte, error)

func (*Conn) RemoteAddr

func (cn *Conn) RemoteAddr() net.Addr

func (*Conn) SetNetConn

func (cn *Conn) SetNetConn(netConn net.Conn)

func (*Conn) SetTimeout

func (cn *Conn) SetTimeout(rt, wt time.Duration)

type ConnPool

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

func NewConnPool

func NewConnPool(opt *Options) *ConnPool

func (*ConnPool) Close

func (p *ConnPool) Close() error

func (*ConnPool) CloseConn

func (p *ConnPool) CloseConn(cn *Conn) error

func (*ConnPool) FreeLen

func (p *ConnPool) FreeLen() int

FreeLen returns number of free connections.

func (*ConnPool) Get

func (p *ConnPool) Get() (*Conn, bool, error)

Get returns existed connection from the pool or creates a new one.

func (*ConnPool) Len

func (p *ConnPool) Len() int

Len returns total number of connections.

func (*ConnPool) NewConn

func (p *ConnPool) NewConn() (*Conn, error)

func (*ConnPool) Put

func (p *ConnPool) Put(cn *Conn) error

func (*ConnPool) ReapStaleConns

func (p *ConnPool) ReapStaleConns() (int, error)

func (*ConnPool) Remove

func (p *ConnPool) Remove(cn *Conn) error

func (*ConnPool) Stats

func (p *ConnPool) Stats() *Stats

type Options

type Options struct {
	Dialer  func() (net.Conn, error)
	OnClose func(*Conn) error

	PoolSize           int
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
	MaxAge             time.Duration
}

type Pooler

type Pooler interface {
	NewConn() (*Conn, error)
	CloseConn(*Conn) error

	Get() (*Conn, bool, error)
	Put(*Conn) error
	Remove(*Conn) error

	Len() int
	FreeLen() int
	Stats() *Stats

	Close() error
}

type SingleConnPool

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

func NewSingleConnPool

func NewSingleConnPool(cn *Conn) *SingleConnPool

func (*SingleConnPool) Close

func (p *SingleConnPool) Close() error

func (*SingleConnPool) CloseConn

func (p *SingleConnPool) CloseConn(*Conn) error

func (*SingleConnPool) FreeLen

func (p *SingleConnPool) FreeLen() int

func (*SingleConnPool) Get

func (p *SingleConnPool) Get() (*Conn, bool, error)

func (*SingleConnPool) Len

func (p *SingleConnPool) Len() int

func (*SingleConnPool) NewConn

func (p *SingleConnPool) NewConn() (*Conn, error)

func (*SingleConnPool) Put

func (p *SingleConnPool) Put(cn *Conn) error

func (*SingleConnPool) Remove

func (p *SingleConnPool) Remove(cn *Conn) error

func (*SingleConnPool) Stats

func (p *SingleConnPool) Stats() *Stats

type Stats

type Stats struct {
	Hits     uint32 // number of times free connection was found in the pool
	Misses   uint32 // number of times free connection was NOT found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalConns uint32 // number of total connections in the pool
	FreeConns  uint32 // number of free connections in the pool
	StaleConns uint32 // number of stale connections removed from the pool
}

Stats contains pool state information and accumulated stats.

type WriteBuffer

type WriteBuffer struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func NewWriteBuffer

func NewWriteBuffer() *WriteBuffer

func (*WriteBuffer) FinishMessage

func (buf *WriteBuffer) FinishMessage()

func (*WriteBuffer) FinishNullParam

func (buf *WriteBuffer) FinishNullParam()

func (*WriteBuffer) FinishParam

func (buf *WriteBuffer) FinishParam()

func (*WriteBuffer) ReadFrom

func (buf *WriteBuffer) ReadFrom(r io.Reader) (int64, error)

func (*WriteBuffer) Reset

func (buf *WriteBuffer) Reset()

func (*WriteBuffer) StartMessage

func (buf *WriteBuffer) StartMessage(c byte)

func (*WriteBuffer) StartParam

func (buf *WriteBuffer) StartParam()

func (*WriteBuffer) Write

func (buf *WriteBuffer) Write(b []byte) (int, error)

func (*WriteBuffer) WriteByte

func (buf *WriteBuffer) WriteByte(c byte) error

func (*WriteBuffer) WriteBytes

func (buf *WriteBuffer) WriteBytes(b []byte)

func (*WriteBuffer) WriteInt16

func (buf *WriteBuffer) WriteInt16(num int16)

func (*WriteBuffer) WriteInt32

func (buf *WriteBuffer) WriteInt32(num int32)

func (*WriteBuffer) WriteString

func (buf *WriteBuffer) WriteString(s string)

Jump to

Keyboard shortcuts

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