connexus

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

connexus

tcp udp 管理

1 基于时间序列选取链接,优先选取长时间未使用的链接,保证链接活跃。

cfg := PoolConfig{
	Cap: 30,
	MaxIdleCap:35,
	Factory: func() (net.Conn, error) { return net.Dial("tcp", "localhost:7777") }
}
pool := NewConnexPool(cfg)

conn,err := pool.Get()

// do something

// 链接会重新放回池中
conn.Close()

// 若希望关闭底层链接
conn.MarkUnusable()
// 再次调用,后底层链接将会关闭,链接不会放入池中
conn.Close()

//关闭连接池,池中的链接将会随之关闭
pool.Close()

Documentation

Index

Constants

View Source
const MaxConnectCount = 20000
View Source
const MaxIdleConnectCount = 25000

Variables

View Source
var (
	ErrClosed = errors.New("pool is closed")
)

Functions

This section is empty.

Types

type Connex

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

func (*Connex) Close

func (c *Connex) Close() error

Close put the connection back to pool if possible. Executed by multi times is ok.

func (*Connex) IsUnusable

func (c *Connex) IsUnusable() bool

func (*Connex) MarkUnusable

func (c *Connex) MarkUnusable()

type Pool

type Pool interface {
	// Get return a new item from the pool. Closing the item puts it back to the pool
	Get() (net.Conn, error)
	// Close close the pool and release all resources
	Close()
	// Len returns the number of items of the pool
	Len() int
}

func NewConnexPool

func NewConnexPool(cfg PoolConfig) (Pool, error)

type PoolConfig

type PoolConfig struct {
	Cap        int
	MaxIdleCap int
	Factory    func() (net.Conn, error)
}

type PriorityQueue

type PriorityQueue []*Connex

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

Jump to

Keyboard shortcuts

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