core

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTcpServer

func NewTcpServer(addr string, opsFunc ...func(h *TcpHandle))

Types

type Pool

type Pool struct {
	sync.RWMutex
	// 连接池 addr -- pool
	Items map[string]*PoolItem
}

func (*Pool) NewItem

func (p *Pool) NewItem(addr string) *PoolItem

创建连接池

type PoolItem

type PoolItem struct {
	sync.RWMutex
	Objs chan *PoolObj
	// 最小数量
	IdMin int
	// 最大数量
	IdMax int
	// 当前数量 总数
	Num      int32
	LifeTime int64
	Addr     string
}

连接池对象

func GetPool

func GetPool(addr string) *PoolItem

func (*PoolItem) Get

func (item *PoolItem) Get() (*PoolObj, error)

获取连接:优先提供空闲,无空闲并且没有达到最大连接数则创建,否则等待最长时间后再获取

func (*PoolItem) Init

func (item *PoolItem) Init()

连接池对象初始化

func (*PoolItem) NewObj

func (item *PoolItem) NewObj() (*PoolObj, error)

新建连接

func (*PoolItem) Recycle

func (item *PoolItem) Recycle(obj *PoolObj)

回收连接

type PoolObj

type PoolObj struct {
	EndTime int64
	Client  *TcpClient
}

连接对象

type TcpClient

type TcpClient struct {
	*TcpHandle
}

func NewTcpClient

func NewTcpClient(addr string) (*TcpClient, error)

type TcpCloseFunc

type TcpCloseFunc func(h *TcpHandle)

type TcpHandle

type TcpHandle struct {
	//value map[string]interface{}
	*common.Cache

	// tcp状态
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTcpHandle

func NewTcpHandle(conn net.Conn) *TcpHandle

func (*TcpHandle) Close

func (h *TcpHandle) Close()

处理关闭

func (*TcpHandle) GetAddr

func (h *TcpHandle) GetAddr() string

获取地址

func (*TcpHandle) GetMid

func (h *TcpHandle) GetMid() uint64

获取消息id

func (*TcpHandle) Send

func (h *TcpHandle) Send(msg *deal.Msg)

包入列

func (*TcpHandle) SetCloseFunc

func (h *TcpHandle) SetCloseFunc(f TcpCloseFunc)

设置断开函数

func (*TcpHandle) SetHandleFunc

func (h *TcpHandle) SetHandleFunc(handleFunc TcpHandleFunc)

设置包处理函数

func (*TcpHandle) SetInitFunc

func (h *TcpHandle) SetInitFunc(f TcpInitFunc)

设置初始化函数

func (*TcpHandle) Status

func (h *TcpHandle) Status() bool

获取连接状态

type TcpHandleFunc

type TcpHandleFunc func(h *TcpHandle, m *deal.Msg)

type TcpInitFunc

type TcpInitFunc func(h *TcpHandle)

Jump to

Keyboard shortcuts

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