Documentation ¶
Index ¶
- func NewConnManager() netInterface.IConnManager
- func NewConnection(server *Service, conn net.Conn, connId uint64, ...) netInterface.IConnection
- func NewService(config *Config) netInterface.IService
- func NewUdpService(config *Config) netInterface.IService
- type AcceptTask
- type AddrConfig
- type Config
- type ConnManager
- func (c *ConnManager) Add(conn netInterface.IConnection)
- func (c *ConnManager) ClearConn()
- func (c *ConnManager) Count() int
- func (c *ConnManager) Get(connId uint64) (netInterface.IConnection, bool)
- func (c *ConnManager) Range(hFunc func(connId uint64, value netInterface.IConnection) bool)
- func (c *ConnManager) Remove(conn netInterface.IConnection)
- func (c *ConnManager) RemoveById(connId uint64)
- type Connection
- func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (c *Connection) GetConnId() uint64
- func (c *Connection) GetHeartTime() time.Time
- func (c *Connection) GetIsClosed() bool
- func (c *Connection) GetLocalAddr() net.Addr
- func (c *Connection) GetNetConn() interface{}
- func (c *Connection) GetNetwork() string
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetPropertyKeys() []string
- func (c *Connection) GetRecInfo() (count, byteSize uint64)
- func (c *Connection) GetRemoteAddr() net.Addr
- func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
- func (c *Connection) GetStartTime() time.Time
- func (c *Connection) OnCompleted(data []byte, count int)
- func (c *Connection) OnReceive(data []byte)
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendData(data []byte, cmdCode string) error
- func (c *Connection) SendDataCall(data []byte, cmdCode string, param interface{}, ...) error
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) Stop()
- type ReceiveTask
- type ReplyTask
- type Service
- func (s *Service) AddConnId() uint64
- func (s *Service) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (s *Service) CallOnConnStart(conn netInterface.IConnection)
- func (s *Service) CallOnConnStop(conn netInterface.IConnection)
- func (s *Service) CallOnReceive(conn netInterface.IConnection, data []byte)
- func (s *Service) CallOnReply(conn netInterface.IConnection, data []byte, isOk bool, cmdCode string, ...)
- func (s *Service) GetAcceptWorkerPool() pools.ITaskWorkerPool
- func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)
- func (s *Service) GetConnMgr() netInterface.IConnManager
- func (s *Service) GetReceiveWorkerPool() pools.ITaskWorkerPool
- func (s *Service) GetReplyWorkerPool() pools.ITaskWorkerPool
- func (s *Service) GetStartTime() time.Time
- func (s *Service) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
- func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
- func (s *Service) SetOnConnStart(hookFunc func(netInterface.IConnection))
- func (s *Service) SetOnConnStop(hookFunc func(netInterface.IConnection))
- func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
- func (s *Service) SetOnReply(...)
- func (s *Service) Start()
- func (s *Service) Stop()
- type UdpConnection
- func (u *UdpConnection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (u *UdpConnection) GetConnId() uint64
- func (u *UdpConnection) GetHeartTime() time.Time
- func (u *UdpConnection) GetIsClosed() bool
- func (u *UdpConnection) GetLocalAddr() net.Addr
- func (u *UdpConnection) GetNetConn() interface{}
- func (u *UdpConnection) GetNetwork() string
- func (u *UdpConnection) GetProperty(key string) (interface{}, error)
- func (u *UdpConnection) GetPropertyKeys() []string
- func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)
- func (u *UdpConnection) GetRemoteAddr() net.Addr
- func (u *UdpConnection) GetRepInfo() (count, byteSize, errCount uint64)
- func (u *UdpConnection) GetStartTime() time.Time
- func (u *UdpConnection) OnCompleted(data []byte, count int)
- func (u *UdpConnection) OnReceive(data []byte)
- func (u *UdpConnection) RemoveProperty(key string)
- func (u *UdpConnection) SendData(data []byte, cmdCode string) error
- func (u *UdpConnection) SendDataCall(data []byte, cmdCode string, param interface{}, ...) error
- func (u *UdpConnection) SetProperty(key string, value interface{})
- func (u *UdpConnection) Start()
- func (u *UdpConnection) Stop()
- type UdpReceiveTask
- type UdpReplyTask
- type UdpService
- func (u *UdpService) AddConnId() uint64
- func (u *UdpService) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (u *UdpService) CallOnConnStart(conn netInterface.IConnection)
- func (u *UdpService) CallOnConnStop(conn netInterface.IConnection)
- func (u *UdpService) CallOnReceive(conn netInterface.IConnection, data []byte)
- func (u *UdpService) CallOnReply(conn netInterface.IConnection, data []byte, isOk bool, cmdCode string, ...)
- func (u *UdpService) GetAcceptWorkerPool() pools.ITaskWorkerPool
- func (u *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)
- func (u *UdpService) GetConnMgr() netInterface.IConnManager
- func (u *UdpService) GetReceiveWorkerPool() pools.ITaskWorkerPool
- func (u *UdpService) GetReplyWorkerPool() pools.ITaskWorkerPool
- func (u *UdpService) GetStartTime() time.Time
- func (u *UdpService) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
- func (u *UdpService) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
- func (u *UdpService) SetOnConnStart(hookFunc func(netInterface.IConnection))
- func (u *UdpService) SetOnConnStop(hookFunc func(netInterface.IConnection))
- func (u *UdpService) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
- func (u *UdpService) SetOnReply(...)
- func (u *UdpService) Start()
- func (u *UdpService) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnection ¶
func NewConnection(server *Service, conn net.Conn, connId uint64, receiveHandler pools.ITaskWorkerPool, replyHandle pools.ITaskWorkerPool, config *Config) netInterface.IConnection
创建连接的方法
Types ¶
type AcceptTask ¶ added in v1.4.1
type AcceptTask struct {
// contains filtered or unexported fields
}
连接接入任务
func (*AcceptTask) GetDuration ¶ added in v1.6.7
func (a *AcceptTask) GetDuration() time.Duration
type AddrConfig ¶ added in v1.5.0
type AddrConfig struct { Addr string //地址端口:192.168.1.24:7018 CertFile string //server.crt 文件路径:TCP支持Tls KeyFile string //server.key 文件路径:TCP支持Tls ClientCer string //配置客户端证书【加入证书会开启客户端验证】 IsTls bool //是否TLS连接 }
Tls配置
type Config ¶
type Config struct { Network string //网络:tcp,udp AddrAry []*AddrConfig //[普通/Tls]监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...] ReceiveWorkerSize uint //(上行处理)工作池中工作线程个数,必须2的N次方 ReceiveTaskQueueSize uint //(上行处理)单个工作队列缓存任务大小 ReceiveOutTime time.Duration //(上行处理)处理任务超时时间 ,IsOutTime=true 时生效 ReplyWorkerSize uint //(下行处理)工作池中工作线程个数,必须2的N次方 ReplyTaskQueueSize uint //(下行处理)单个工作队列缓存任务大小 ReplyOutTime time.Duration //(下行处理)超时时间(完整任务) ,IsOutTime=true 时生效 AcceptWorkerSize uint //(连接接入处理)工作池中工作线程个数[tcp使用],必须2的N次方 AcceptTaskQueueSize uint //(连接接入处理)单个工作队列缓存任务大小[tcp使用] AcceptOutTime time.Duration //(连接接入处理)超时时间,IsOutTime=true 时生效 BufferSize uint //缓存尺寸(字节) BytesCacheSize uint //分包缓存大小 HDataCache bool //是否启用处理数据缓存优化[注意:启用后SetOnReceive 处理方法使用协程会导致数据错乱] SendOutTime time.Duration //(下行处理网络)超时时间 IsOutTime bool //是否需要支持超时 OverflowDiscard bool //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】 }
配置
func DefaultConfig ¶ added in v1.2.0
普通网络配置
func NewConfig ¶ added in v1.5.0
func NewConfig(network string, addrAry []*AddrConfig) *Config
普通、Tls 网络都支持配置
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
连接管理模块
func (*ConnManager) Get ¶
func (c *ConnManager) Get(connId uint64) (netInterface.IConnection, bool)
利用ConnID获取链接
func (*ConnManager) Range ¶ added in v1.3.1
func (c *ConnManager) Range(hFunc func(connId uint64, value netInterface.IConnection) bool)
遍历连接
func (*ConnManager) RemoveById ¶ added in v1.7.5
func (c *ConnManager) RemoveById(connId uint64)
删除连接
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
连接结构体
func (*Connection) CallLogHandle ¶ added in v1.2.0
func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
调用异常处理
func (*Connection) GetHeartTime ¶ added in v1.1.1
func (c *Connection) GetHeartTime() time.Time
获取心跳时间
func (*Connection) GetIsClosed ¶ added in v1.4.1
func (c *Connection) GetIsClosed() bool
获取的状态(ture:关闭状态,false:未关闭)
func (*Connection) GetLocalAddr ¶ added in v1.2.2
func (c *Connection) GetLocalAddr() net.Addr
获取本地地址信息
func (*Connection) GetNetConn ¶
func (c *Connection) GetNetConn() interface{}
从当前连接获取原始的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)
获取链接属性
func (*Connection) GetPropertyKeys ¶ added in v1.6.3
func (c *Connection) GetPropertyKeys() []string
获取所有属性key
func (*Connection) GetRecInfo ¶ added in v1.4.1
func (c *Connection) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*Connection) GetRepInfo ¶ added in v1.4.1
func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
下行当前处理的包总数(处理后),总大小(字节)
func (*Connection) GetStartTime ¶ added in v1.4.1
func (c *Connection) GetStartTime() time.Time
获取连接启动时间
func (*Connection) OnReceive ¶ added in v1.6.1
func (c *Connection) OnReceive(data []byte)
数据上传了完整一包的回调
func (*Connection) SendData ¶
func (c *Connection) SendData(data []byte, cmdCode string) error
直接将数据发送数据给远程的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
直接将数据发送数据给远程的TCP客户端(带参数和回调) data 下发数据 param 下发需要回调携带参数 cmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] callFunc 下发后回调函数
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type ReceiveTask ¶ added in v1.4.1
type ReceiveTask struct { OnCompleted func(data []byte, count int) //接收到一次数据(未分包开始处理不确定是否完成) // contains filtered or unexported fields }
客户端请求内容
func (*ReceiveTask) GetDuration ¶ added in v1.6.7
func (r *ReceiveTask) GetDuration() time.Duration
type ReplyTask ¶ added in v1.4.1
type ReplyTask struct {
// contains filtered or unexported fields
}
发送数据TCP
func (*ReplyTask) GetDuration ¶ added in v1.6.7
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
IServer 接口实现,定义一个Server服务类
func (*Service) CallLogHandle ¶ added in v1.2.0
func (s *Service) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
错误消息处理
func (*Service) CallOnConnStart ¶
func (s *Service) CallOnConnStart(conn netInterface.IConnection)
调用连接OnConnStart Hook函数
func (*Service) CallOnConnStop ¶
func (s *Service) CallOnConnStop(conn netInterface.IConnection)
调用连接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)
下发后回调
func (*Service) GetAcceptWorkerPool ¶ added in v1.7.5
func (s *Service) GetAcceptWorkerPool() pools.ITaskWorkerPool
[TCP特有]连接接收处理器(工作池)
func (*Service) GetConn ¶
func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)
获取连接
func (*Service) GetReceiveWorkerPool ¶ added in v1.7.5
func (s *Service) GetReceiveWorkerPool() pools.ITaskWorkerPool
消息处理模块(工作池)
func (*Service) GetReplyWorkerPool ¶ added in v1.7.5
func (s *Service) GetReplyWorkerPool() pools.ITaskWorkerPool
消息发送处理器(工作池)
func (*Service) SetCreateReceiver ¶
func (s *Service) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
设置创建分包策略方法
func (*Service) SetLogHandle ¶ added in v1.2.0
func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
设置日志处理
func (*Service) SetOnConnStart ¶
func (s *Service) SetOnConnStart(hookFunc func(netInterface.IConnection))
设置该Server的连接创建时Hook函数
func (*Service) SetOnConnStop ¶
func (s *Service) SetOnConnStop(hookFunc func(netInterface.IConnection))
设置该Server的连接断开时的Hook函数
func (*Service) SetOnReceive ¶ added in v1.6.1
func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*Service) SetOnReply ¶ added in v1.6.1
func (s *Service) SetOnReply(hookFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error))
type UdpConnection ¶
type UdpConnection struct {
// contains filtered or unexported fields
}
func NewUdpConnection ¶
func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, receiveHandler pools.ITaskWorkerPool, replyHandle pools.ITaskWorkerPool, config *Config) *UdpConnection
Udp连接
func (*UdpConnection) CallLogHandle ¶ added in v1.2.0
func (u *UdpConnection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
调用异常处理
func (*UdpConnection) GetHeartTime ¶ added in v1.1.1
func (u *UdpConnection) GetHeartTime() time.Time
获取心跳时间
func (*UdpConnection) GetIsClosed ¶ added in v1.4.1
func (u *UdpConnection) GetIsClosed() bool
获取的状态(ture:关闭状态,false:未关闭)
func (*UdpConnection) GetLocalAddr ¶ added in v1.2.2
func (u *UdpConnection) GetLocalAddr() net.Addr
获取本地地址信息
func (*UdpConnection) GetNetConn ¶ added in v1.2.2
func (u *UdpConnection) GetNetConn() interface{}
获取网络连接
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)
获取链接属性
func (*UdpConnection) GetPropertyKeys ¶ added in v1.6.3
func (u *UdpConnection) GetPropertyKeys() []string
获取所有属性key
func (*UdpConnection) GetRecInfo ¶ added in v1.4.1
func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*UdpConnection) GetRepInfo ¶ added in v1.4.1
func (u *UdpConnection) GetRepInfo() (count, byteSize, errCount uint64)
下行当前处理的包总数(处理后),总大小(字节)
func (*UdpConnection) GetStartTime ¶ added in v1.4.1
func (u *UdpConnection) GetStartTime() time.Time
获取连接启动时间
func (*UdpConnection) OnCompleted ¶
func (u *UdpConnection) OnCompleted(data []byte, count int)
Udp 不需要分包
func (*UdpConnection) OnReceive ¶ added in v1.6.1
func (u *UdpConnection) OnReceive(data []byte)
数据上传完整的一包处理
func (*UdpConnection) SendData ¶
func (u *UdpConnection) SendData(data []byte, cmdCode string) error
直接将数据发送数据给远程的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
直接将数据发送数据给远程的TCP客户端(带参数和回调) data 下发数据 param 下发需要回调携带参数 cmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] callFunc 下发后回调函数
func (*UdpConnection) SetProperty ¶
func (u *UdpConnection) SetProperty(key string, value interface{})
设置链接属性
type UdpReceiveTask ¶ added in v1.4.1
type UdpReceiveTask struct { OnCompleted func(data []byte, count int) //接收到一次数据(未分包开始处理不确定是否完成) // contains filtered or unexported fields }
func (*UdpReceiveTask) GetDuration ¶ added in v1.6.7
func (u *UdpReceiveTask) GetDuration() time.Duration
func (*UdpReceiveTask) GetTaskId ¶ added in v1.4.1
func (u *UdpReceiveTask) GetTaskId() uint64
获取连接id
type UdpReplyTask ¶ added in v1.4.1
type UdpReplyTask struct {
// contains filtered or unexported fields
}
Udp响应
func (*UdpReplyTask) GetDuration ¶ added in v1.6.7
func (u *UdpReplyTask) GetDuration() time.Duration
type UdpService ¶
type UdpService struct {
// contains filtered or unexported fields
}
IServer 接口实现,定义一个Server服务类
func (*UdpService) CallLogHandle ¶ added in v1.2.0
func (u *UdpService) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
错误消息处理
func (*UdpService) CallOnConnStart ¶
func (u *UdpService) CallOnConnStart(conn netInterface.IConnection)
调用连接OnConnStart Hook函数
func (*UdpService) CallOnConnStop ¶
func (u *UdpService) CallOnConnStop(conn netInterface.IConnection)
调用连接OnConnStop Hook函数
func (*UdpService) CallOnReceive ¶ added in v1.6.1
func (u *UdpService) CallOnReceive(conn netInterface.IConnection, data []byte)
数据上传完成回调
func (*UdpService) CallOnReply ¶ added in v1.6.1
func (u *UdpService) CallOnReply(conn netInterface.IConnection, data []byte, isOk bool, cmdCode string, param interface{}, err error)
下发后回调
func (*UdpService) GetAcceptWorkerPool ¶ added in v1.7.5
func (u *UdpService) GetAcceptWorkerPool() pools.ITaskWorkerPool
[TCP特有]连接接收处理器(工作池)
func (*UdpService) GetConn ¶
func (u *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)
func (*UdpService) GetReceiveWorkerPool ¶ added in v1.7.5
func (u *UdpService) GetReceiveWorkerPool() pools.ITaskWorkerPool
消息处理模块(工作池)
func (*UdpService) GetReplyWorkerPool ¶ added in v1.7.5
func (u *UdpService) GetReplyWorkerPool() pools.ITaskWorkerPool
消息发送处理器(工作池)
func (*UdpService) GetStartTime ¶ added in v1.4.1
func (u *UdpService) GetStartTime() time.Time
获取连接启动时间
func (*UdpService) SetCreateReceiver ¶
func (u *UdpService) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
设置创建分包策略方法
func (*UdpService) SetLogHandle ¶ added in v1.2.0
func (u *UdpService) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
func (*UdpService) SetOnConnStart ¶
func (u *UdpService) SetOnConnStart(hookFunc func(netInterface.IConnection))
设置该Server的连接创建时Hook函数
func (*UdpService) SetOnConnStop ¶
func (u *UdpService) SetOnConnStop(hookFunc func(netInterface.IConnection))
设置该Server的连接断开时的Hook函数
func (*UdpService) SetOnReceive ¶ added in v1.6.1
func (u *UdpService) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*UdpService) SetOnReply ¶ added in v1.6.1
func (u *UdpService) SetOnReply(hookFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error))