Documentation
¶
Overview ¶
一個 tcp 連接池
Index ¶
- type Conn
- type IPool
- type IPoolTemplate
- type PoolTemplate
- func (p *PoolTemplate) Close(c net.Conn) error
- func (p *PoolTemplate) Conect() (net.Conn, error)
- func (p *PoolTemplate) Interval() time.Duration
- func (p *PoolTemplate) MinInterval() time.Duration
- func (p *PoolTemplate) Ping(*Conn) error
- func (p *PoolTemplate) PingInterval() time.Duration
- func (p *PoolTemplate) Resize(use, free int) int
- func (p *PoolTemplate) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPool ¶
type IPool interface {
//從 連接池 中 獲取一個連接
Get() (*Conn, error)
//將 連接 返回給 連接池
Put(*Conn)
//釋放 連接池 所有資源 此後 連接池不能再被使用
Close()
}
連接池 接口
type IPoolTemplate ¶
type IPoolTemplate interface {
//連接池 將使用此 函數 連接 服務器
Conect() (net.Conn, error)
//連接池 將使用此 函數 斷開 連接
Close(net.Conn) error
//連接池 將使用此 函數 ping 服務器
Ping(*Conn) error
//連接池 中的連接 多久自動執行一次 ping
//返回 0 將不會執行ping
//返回值 必須 恆定
PingInterval() time.Duration
//多久 未活動的 連接 會被 釋放
//返回 0 永不超時
//返回值 必須 恆定
Timeout() time.Duration
//連接池 執行縮擴容 操作 的最小 執行週期
MinInterval() time.Duration
//連接池 多久執行一次自動 縮擴容
//返回 0 不執行
//返回值 必須 恆定
Interval() time.Duration
//是否需要 縮擴容
//返回 0 不需要擴容
//返回 >0 擴容 |n|
//返回 <0 縮容 |n|
Resize(use, free int) int
}
連接池 模板 定義了 連接池 工作細節
type PoolTemplate ¶
type PoolTemplate struct {
// contains filtered or unexported fields
}
默認的 連接池 模板
func NewPoolTemplate ¶
創建一個 默認的 連接池 模板
func (*PoolTemplate) Interval ¶
func (p *PoolTemplate) Interval() time.Duration
func (*PoolTemplate) MinInterval ¶
func (p *PoolTemplate) MinInterval() time.Duration
func (*PoolTemplate) Ping ¶
func (p *PoolTemplate) Ping(*Conn) error
func (*PoolTemplate) PingInterval ¶
func (p *PoolTemplate) PingInterval() time.Duration
func (*PoolTemplate) Resize ¶
func (p *PoolTemplate) Resize(use, free int) int
func (*PoolTemplate) Timeout ¶
func (p *PoolTemplate) Timeout() time.Duration
Click to show internal directories.
Click to hide internal directories.