netService

package
v1.8.30 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HKey = "#CallKey#" // 回调返回Key
)

Variables

This section is empty.

Functions

func NewConnManager

func NewConnManager() netInterface.IConnManager

NewConnManager 实例化管理

func NewService

func NewService(config *Config) netInterface.IService

NewService 实例化TCP服务类

func NewUdpService

func NewUdpService(config *Config) netInterface.IService

NewUdpService 创建UDP服务

Types

type AddrConfig added in v1.5.0

type AddrConfig struct {
	Addr      string      //地址端口:192.168.1.24:7018
	TlsConfig *tls.Config //tls配置
	IsTls     bool        //是否开启tls
}

AddrConfig Tls配置

type Config

type Config struct {
	Network              string        //网络:tcp,udp,tls
	AddrAry              []*AddrConfig //[普通/Tls]监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...]
	ReceiveWorkerSize    uint          //(上行处理)工作池中工作线程个数,必须2的N次方
	ReceiveTaskQueueSize uint          //(上行处理)单个工作队列缓存任务大小
	ReplyWorkerSize      uint          //(下行处理)工作池中工作线程个数,必须2的N次方
	ReplyTaskQueueSize   uint          //(下行处理)单个工作队列缓存任务大小
	AcceptWorkerSize     uint          //(连接接入处理)工作池中工作线程个数[tcp使用],必须2的N次方
	AcceptTaskQueueSize  uint          //(连接接入处理)单个工作队列缓存任务大小[tcp使用]
	BufferSize           int           //缓存尺寸(字节)
	SendOutTime          time.Duration //(下行处理网络)超时时间
	OverflowDiscard      bool          //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】
	SendRetryCount       int           //发送遇到临时错误失败重试次数
	KeepTime             time.Duration //保持时间,(注:服务主要是是否能读取数据确认连接是否有存在必要)
	HDataCache           bool          //默认 true, 注意:调用 SetOnReceive 的方法是否新申请内存[false:新申请内存,处理函数可以另外开启协程处理;true:不申请新内存,处理函数不可以另外开启协程处理]
}

Config 配置

func DefaultConfig added in v1.2.0

func DefaultConfig(network string, addrAry []string) *Config

DefaultConfig 普通网络配置

func NewConfig added in v1.5.0

func NewConfig(network string, addrAry []*AddrConfig) *Config

NewConfig 普通、Tls 网络都支持配置

type ConnManager

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

ConnManager 连接管理模块

func (*ConnManager) Add

Add 添加链接[新连接处理]

func (*ConnManager) ClearConn

func (c *ConnManager) ClearConn()

ClearConn 清除并停止所有连接

func (*ConnManager) Count added in v1.4.1

func (c *ConnManager) Count() int32

Count 获取个数

func (*ConnManager) Get

func (c *ConnManager) Get(connId uint64) (netInterface.IConnection, bool)

Get 利用ConnID获取链接

func (*ConnManager) Range added in v1.3.1

func (c *ConnManager) Range(hFunc func(connId uint64, value netInterface.IConnection) bool)

Range 遍历连接

func (*ConnManager) Remove

func (c *ConnManager) Remove(conn netInterface.IConnection) bool

Remove 删除连接

func (*ConnManager) RemoveById added in v1.7.5

func (c *ConnManager) RemoveById(connId uint64) bool

RemoveById 删除连接

type Connection

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

Connection 连接结构体

func NewConnection

func NewConnection(server *Service, conn net.Conn, connId uint64) *Connection

NewConnection 创建连接的方法

func (*Connection) CallLogHandle added in v1.2.0

func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 调用异常处理

func (*Connection) GetConnId

func (c *Connection) GetConnId() uint64

GetConnId 获取当前连接ID

func (*Connection) GetHeartTime added in v1.1.1

func (c *Connection) GetHeartTime() time.Time

GetHeartTime 连接最后一次接收数据时间

func (*Connection) GetIsClosed added in v1.4.1

func (c *Connection) GetIsClosed() bool

GetIsClosed 获取的状态[脏读][ture:关闭状态,false:未关闭]

func (*Connection) GetLocalAddr added in v1.2.2

func (c *Connection) GetLocalAddr() net.Addr

GetLocalAddr 获取本地地址信息

func (*Connection) GetNetConn

func (c *Connection) GetNetConn() interface{}

GetNetConn 从当前连接获取原始的socket TCPConn

func (*Connection) GetNetwork added in v1.6.6

func (c *Connection) GetNetwork() string

GetNetwork 获取网络类型

func (*Connection) GetProperty

func (c *Connection) GetProperty(key string) (interface{}, error)

GetProperty 获取链接属性

func (*Connection) GetPropertyKeys added in v1.6.3

func (c *Connection) GetPropertyKeys() []string

GetPropertyKeys 获取所有属性key

func (*Connection) GetRecInfo added in v1.4.1

func (c *Connection) GetRecInfo() (count, byteSize uint64)

GetRecInfo 上行当前处理的包总数(处理前,1开始),总大小(字节)

func (*Connection) GetRemoteAddr

func (c *Connection) GetRemoteAddr() net.Addr

GetRemoteAddr 获取远程客户端地址信息

func (*Connection) GetRepInfo added in v1.4.1

func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)

GetRepInfo 下行当前处理的包总数(处理后),总大小(字节)

func (*Connection) GetSendTime added in v1.8.17

func (c *Connection) GetSendTime() time.Time

GetSendTime 连接最后一次发送数据时间

func (*Connection) GetStartTime added in v1.4.1

func (c *Connection) GetStartTime() time.Time

GetStartTime 连接建立时间

func (*Connection) Incr added in v1.8.7

func (c *Connection) Incr(val int64) int64

Incr 连接提供给业务作为流水号使用,循环累加,(val 为正数为递增,val为负数为递减,val为0则获取值)

func (*Connection) OnReceive added in v1.6.1

func (c *Connection) OnReceive(data []byte)

OnReceive 处理

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

RemoveProperty 移除链接属性

func (*Connection) SendData

func (c *Connection) SendData(data []byte, cmdCode string) error

SendData 发送数据给远程的TCP客户端 Data 下发数据 CmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。]

func (*Connection) SendDataCall

func (c *Connection) SendDataCall(data []byte, cmdCode string, param interface{}, callFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error)) error

SendDataCall 发送数据给远程的TCP客户端(带参数和回调) Data 下发数据 Param 下发需要回调携带参数 CmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] CallFunc 下发后回调函数

func (*Connection) SetProperty

func (c *Connection) SetProperty(key string, value interface{})

SetProperty 设置链接属性

func (*Connection) Start

func (c *Connection) Start()

Start 启动连接,让当前连接开始工作[只会调用一次]

func (*Connection) Stop

func (c *Connection) Stop()

Stop 停止连接,结束当前连接状态M

type Service

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

Service 接口实现,定义一个Server服务类

func (*Service) CallLogHandle added in v1.2.0

func (s *Service) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 错误消息处理

func (*Service) CallOnConnStart

func (s *Service) CallOnConnStart(conn netInterface.IConnection)

CallOnConnStart 调用连接OnConnStart Hook函数

func (*Service) CallOnConnStop

func (s *Service) CallOnConnStop(conn netInterface.IConnection)

CallOnConnStop 调用连接OnConnStop Hook函数

func (*Service) CallOnReceive added in v1.6.1

func (s *Service) CallOnReceive(conn netInterface.IConnection, data []byte)

CallOnReceive 数据上传完成回调

func (*Service) CallOnReply added in v1.6.1

func (s *Service) CallOnReply(conn netInterface.IConnection, data []byte, isOk bool, cmdCode string, param interface{}, err error)

CallOnReply 下发后回调

func (*Service) GetConn

func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)

GetConn 获取连接

func (*Service) GetConnMgr

func (s *Service) GetConnMgr() netInterface.IConnManager

GetConnMgr 得到链接管理

func (*Service) GetIsStart added in v1.8.14

func (s *Service) GetIsStart() bool

GetIsStart 获取是否启动[true 启动,false 未启动]

func (*Service) GetStartTime added in v1.4.1

func (s *Service) GetStartTime() time.Time

GetStartTime 获取连接启动时间

func (*Service) SetHandleStrategy added in v1.8.17

func (s *Service) SetHandleStrategy(hookFunc func(netInterface.IConnection, []byte) *netInterface.StrategyData)

SetHandleStrategy 设置处理策略

func (*Service) SetLogHandle added in v1.2.0

func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))

SetLogHandle 设置日志处理

func (*Service) SetOnConnStart

func (s *Service) SetOnConnStart(hookFunc func(netInterface.IConnection))

SetOnConnStart 设置该Server的连接创建时Hook函数

func (*Service) SetOnConnStop

func (s *Service) SetOnConnStop(hookFunc func(netInterface.IConnection))

SetOnConnStop 设置该Server的连接断开时的Hook函数

func (*Service) SetOnReceive added in v1.6.1

func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))

SetOnReceive 数据上传完成处理函数[分包后]

func (*Service) SetOnReply added in v1.6.1

func (s *Service) SetOnReply(hookFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error))

SetOnReply 数据下发后回调

func (*Service) Start

func (s *Service) Start()

Start 开启网络服务

func (*Service) Stop

func (s *Service) Stop()

Stop 停止服务

func (*Service) ToMap added in v1.8.17

func (s *Service) ToMap() map[string]int64

ToMap 获取内部日志

type UdpConnection

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

UdpConnection 连接结构体

func NewUdpConnection

func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr) *UdpConnection

NewUdpConnection Udp连接

func (*UdpConnection) CallLogHandle added in v1.2.0

func (u *UdpConnection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 调用异常处理

func (*UdpConnection) GetConnId

func (u *UdpConnection) GetConnId() uint64

GetConnId 获取当前连接ID

func (*UdpConnection) GetHeartTime added in v1.1.1

func (u *UdpConnection) GetHeartTime() time.Time

GetHeartTime 连接最后一次接收数据时间

func (*UdpConnection) GetIsClosed added in v1.4.1

func (u *UdpConnection) GetIsClosed() bool

GetIsClosed 获取的状态[脏读](ture:关闭状态,false:未关闭)

func (*UdpConnection) GetLocalAddr added in v1.2.2

func (u *UdpConnection) GetLocalAddr() net.Addr

GetLocalAddr 获取本地地址信息

func (*UdpConnection) GetNetConn added in v1.2.2

func (u *UdpConnection) GetNetConn() interface{}

GetNetConn 获取网络连接

func (*UdpConnection) GetNetwork added in v1.6.6

func (u *UdpConnection) GetNetwork() string

GetNetwork 获取网络类型

func (*UdpConnection) GetProperty

func (u *UdpConnection) GetProperty(key string) (interface{}, error)

GetProperty 获取链接属性

func (*UdpConnection) GetPropertyKeys added in v1.6.3

func (u *UdpConnection) GetPropertyKeys() []string

GetPropertyKeys 获取所有属性key

func (*UdpConnection) GetRecInfo added in v1.4.1

func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)

GetRecInfo 上行当前处理的包总数(处理前,1开始),总大小(字节)

func (*UdpConnection) GetRemoteAddr

func (u *UdpConnection) GetRemoteAddr() net.Addr

GetRemoteAddr 获取远程客户端地址信息

func (*UdpConnection) GetRepInfo added in v1.4.1

func (u *UdpConnection) GetRepInfo() (count, byteSize, errCount uint64)

GetRepInfo 下行当前处理的包总数(处理后),总大小(字节)

func (*UdpConnection) GetSendTime added in v1.8.17

func (u *UdpConnection) GetSendTime() time.Time

GetSendTime 连接最后一次发送数据时间

func (*UdpConnection) GetStartTime added in v1.4.1

func (u *UdpConnection) GetStartTime() time.Time

GetStartTime 连接建立时间

func (*UdpConnection) Incr added in v1.8.7

func (u *UdpConnection) Incr(val int64) int64

Incr 连接提供给业务作为流水号使用,循环累加,(val 为正数为递增,val为负数为递减,val为0则获取值)

func (*UdpConnection) OnReceive added in v1.6.1

func (u *UdpConnection) OnReceive(data []byte)

OnReceive 数据上传完整的一包处理

func (*UdpConnection) RemoveProperty

func (u *UdpConnection) RemoveProperty(key string)

RemoveProperty 移除链接属性

func (*UdpConnection) SendData

func (u *UdpConnection) SendData(data []byte, cmdCode string) error

SendData 发送数据给远程的TCP客户端 Data 下发数据 CmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。]

func (*UdpConnection) SendDataCall

func (u *UdpConnection) SendDataCall(data []byte, cmdCode string, param interface{}, callFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error)) error

SendDataCall 发送数据给远程的UDP客户端(带参数和回调) Data 下发数据 Param 下发需要回调携带参数 CmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] CallFunc 下发后回调函数

func (*UdpConnection) SetProperty

func (u *UdpConnection) SetProperty(key string, value interface{})

SetProperty 设置链接属性

func (*UdpConnection) Start

func (u *UdpConnection) Start()

Start 启动连接,让当前连接开始工作[只会调用一次]

func (*UdpConnection) Stop

func (u *UdpConnection) Stop()

Stop 停止连接,结束当前连接状态

type UdpService

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

UdpService 接口实现,定义一个Server服务类

func (*UdpService) CallLogHandle added in v1.2.0

func (s *UdpService) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 错误消息处理

func (*UdpService) CallOnConnStart

func (s *UdpService) CallOnConnStart(conn netInterface.IConnection)

CallOnConnStart 调用连接OnConnStart Hook函数

func (*UdpService) CallOnConnStop

func (s *UdpService) CallOnConnStop(conn netInterface.IConnection)

CallOnConnStop 调用连接OnConnStop Hook函数

func (*UdpService) CallOnReceive added in v1.6.1

func (s *UdpService) CallOnReceive(conn netInterface.IConnection, data []byte)

CallOnReceive 数据上传完成回调

func (*UdpService) CallOnReply added in v1.6.1

func (s *UdpService) CallOnReply(conn netInterface.IConnection, data []byte, isOk bool, cmdCode string, param interface{}, err error)

CallOnReply 下发后回调

func (*UdpService) GetConn

func (s *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)

GetConn 获取连接

func (*UdpService) GetConnMgr

func (s *UdpService) GetConnMgr() netInterface.IConnManager

GetConnMgr 得到链接管理

func (*UdpService) GetIsStart added in v1.8.14

func (s *UdpService) GetIsStart() bool

GetIsStart 获取是否启动[true 启动,false 未启动]

func (*UdpService) GetStartTime added in v1.4.1

func (s *UdpService) GetStartTime() time.Time

GetStartTime 获取连接启动时间

func (*UdpService) SetHandleStrategy added in v1.8.17

func (s *UdpService) SetHandleStrategy(hookFunc func(netInterface.IConnection, []byte) *netInterface.StrategyData)

SetHandleStrategy 设置处理策略

func (*UdpService) SetLogHandle added in v1.2.0

func (s *UdpService) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))

SetLogHandle 内部日志输出

func (*UdpService) SetOnConnStart

func (s *UdpService) SetOnConnStart(hookFunc func(netInterface.IConnection))

SetOnConnStart 设置该Server的连接创建时Hook函数

func (*UdpService) SetOnConnStop

func (s *UdpService) SetOnConnStop(hookFunc func(netInterface.IConnection))

SetOnConnStop 设置该Server的连接断开时的Hook函数

func (*UdpService) SetOnReceive added in v1.6.1

func (s *UdpService) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))

SetOnReceive 数据上传完成处理函数[分包后]

func (*UdpService) SetOnReply added in v1.6.1

func (s *UdpService) SetOnReply(hookFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error))

SetOnReply 数据下发后回调

func (*UdpService) Start

func (s *UdpService) Start()

Start 开启网络服务

func (*UdpService) Stop

func (s *UdpService) Stop()

Stop 停止服务

func (*UdpService) ToMap added in v1.8.17

func (s *UdpService) ToMap() map[string]int64

ToMap 获取内部日志

Jump to

Keyboard shortcuts

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