Documentation ¶
Index ¶
- func NewConnManager() netInterface.IConnManager
- func NewConnection(server *Service, conn net.Conn, connId uint64, ...) netInterface.IConnection
- func NewService(config *Config) netInterface.IService
- func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, ...) netInterface.IConnection
- 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(key uint64, value netInterface.IConnection) bool)
- func (c *ConnManager) Remove(conn netInterface.IConnection)
- type Connection
- func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (c *Connection) GetBytesCache() *bytes.Buffer
- 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) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetRecInfo() (count, byteSize uint64)
- func (c *Connection) GetReceiver() []netInterface.IReceiver
- 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, offset int, count int)
- func (c *Connection) OnReceiveCompleted(data []byte)
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendData(data []byte) error
- func (c *Connection) SendDataCall(data []byte, 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) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)
- func (s *Service) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, ...)
- func (s *Service) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)
- func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)
- func (s *Service) GetConnMgr() netInterface.IConnManager
- func (s *Service) GetRecInfo() (count, byteSize uint64)
- func (s *Service) GetRepInfo() (count, byteSize, errCount uint64)
- func (s *Service) GetStartTime() time.Time
- func (s *Service) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, ...)
- 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) SetOnReceiveCompleted(hookFunc func(netInterface.IConnection, []byte))
- func (s *Service) SetOnReplyCompleted(hookFunc func(netInterface.IConnection, []byte, interface{}, bool, error))
- func (s *Service) Start()
- func (s *Service) Stop()
- type UdpConnection
- func (u *UdpConnection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (u *UdpConnection) GetBytesCache() *bytes.Buffer
- 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) GetProperty(key string) (interface{}, error)
- func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)
- func (u *UdpConnection) GetRecPackCount() 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, offset int, count int)
- func (u *UdpConnection) OnReceiveCompleted(data []byte)
- func (u *UdpConnection) RemoveProperty(key string)
- func (u *UdpConnection) SendData(data []byte) error
- func (u *UdpConnection) SendDataCall(data []byte, 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) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)
- func (u *UdpService) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, ...)
- func (u *UdpService) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)
- func (u *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)
- func (u *UdpService) GetConnMgr() netInterface.IConnManager
- func (u *UdpService) GetRecInfo() (count, byteSize uint64)
- func (u *UdpService) GetRepInfo() (count, byteSize, errCount uint64)
- func (u *UdpService) GetStartTime() time.Time
- func (u *UdpService) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, ...)
- 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) SetOnReceiveCompleted(hookFunc func(netInterface.IConnection, []byte))
- func (u *UdpService) SetOnReplyCompleted(hookFunc func(netInterface.IConnection, []byte, interface{}, bool, error))
- 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
创建连接的方法
func NewUdpConnection ¶
func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, receiveHandler pools.ITaskWorkerPool, replyHandle pools.ITaskWorkerPool, config *Config) netInterface.IConnection
Udp连接
Types ¶
type AcceptTask ¶ added in v1.4.1
type AcceptTask struct {
// contains filtered or unexported fields
}
连接接入任务
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 //(上行处理)工作池中工作线程个数 ReceiveTaskQueueSize uint //(上行处理)单个工作队列缓存任务大小 ReceiveOutTime time.Duration //(上行处理)处理任务超时时间 ,IsOutTime=true 时生效 ReplyWorkerSize uint //(下行处理)工作池中工作线程个数 ReplyTaskQueueSize uint //(下行处理)单个工作队列缓存任务大小 ReplyOutTime time.Duration //(下行处理)超时时间(完整任务) ,IsOutTime=true 时生效 AcceptWorkerSize uint //(连接接入处理)工作池中工作线程个数[tcp使用] AcceptTaskQueueSize uint //(连接接入处理)单个工作队列缓存任务大小[tcp使用] AcceptOutTime time.Duration //(连接接入处理)超时时间,IsOutTime=true 时生效 BufferSize uint //缓存尺寸(字节) BytesCacheSize uint //分包缓存大小 SendOutTime time.Duration //(下行处理网络)超时时间 IsOutTime bool //是否需要支持超时 }
配置
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(key uint64, value netInterface.IConnection) bool)
遍历连接
type Connection ¶
type Connection struct { Receiver []netInterface.IReceiver //分包器 // 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) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
获取链接属性
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) OnCompleted ¶
func (c *Connection) OnCompleted(data []byte, offset int, count int)
数据上传处理
func (*Connection) OnReceiveCompleted ¶
func (c *Connection) OnReceiveCompleted(data []byte)
数据上传了完整一包的回调
func (*Connection) SendData ¶
func (c *Connection) SendData(data []byte) error
直接将Message数据发送数据给远程的TCP客户端
func (*Connection) SendDataCall ¶
func (c *Connection) SendDataCall(data []byte, param interface{}, callFunc func(netInterface.IConnection, bool, interface{}, error)) error
直接将Message数据发送数据给远程的TCP客户端(带参数和回调)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type ReceiveTask ¶ added in v1.4.1
type ReceiveTask struct {
// contains filtered or unexported fields
}
客户端请求内容
type ReplyTask ¶ added in v1.4.1
type ReplyTask struct {
// contains filtered or unexported fields
}
发送数据TCP
type Service ¶
type Service struct { AcceptHandle pools.ITaskWorkerPool //连接处理池 // 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) CallOnReceiveCompleted ¶
func (s *Service) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)
数据上传完成回调
func (*Service) CallOnReplyCompleted ¶ added in v1.2.0
func (s *Service) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, err error)
下发后回调
func (*Service) GetAcceptQueueCount ¶ added in v1.4.1
获取连接接入队列剩余数
func (*Service) GetConn ¶
func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)
获取连接
func (*Service) GetRecInfo ¶ added in v1.4.1
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*Service) GetRepInfo ¶ added in v1.4.1
下行当前处理的包总数(处理后),总大小(字节),异常数
func (*Service) GetTotalQueueCount ¶ added in v1.2.0
func (s *Service) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, replyCount int64, replyTotalCount, replyOutTimeCount uint64)
获取队列剩余数
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) SetOnReceiveCompleted ¶
func (s *Service) SetOnReceiveCompleted(hookFunc func(netInterface.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*Service) SetOnReplyCompleted ¶ added in v1.2.0
func (s *Service) SetOnReplyCompleted(hookFunc func(netInterface.IConnection, []byte, interface{}, bool, error))
type UdpConnection ¶
type UdpConnection struct {
// contains filtered or unexported fields
}
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) GetProperty ¶
func (u *UdpConnection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*UdpConnection) GetRecInfo ¶ added in v1.4.1
func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*UdpConnection) GetRecPackCount ¶ added in v1.4.1
func (u *UdpConnection) GetRecPackCount() 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, offset int, count int)
数据上次一包(未分包开始处理不确定是否完成)
func (*UdpConnection) OnReceiveCompleted ¶
func (u *UdpConnection) OnReceiveCompleted(data []byte)
数据上传完整的一包处理
func (*UdpConnection) SendDataCall ¶
func (u *UdpConnection) SendDataCall(data []byte, param interface{}, callFunc func(netInterface.IConnection, bool, interface{}, error)) error
发送消息到客户端带回调
func (*UdpConnection) SetProperty ¶
func (u *UdpConnection) SetProperty(key string, value interface{})
设置链接属性
type UdpReceiveTask ¶ added in v1.4.1
type UdpReceiveTask struct {
// contains filtered or unexported fields
}
func (*UdpReceiveTask) GetConnection ¶ added in v1.4.1
func (u *UdpReceiveTask) GetConnection() (netInterface.IConnection, bool)
获取请求连接信息
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响应
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) CallOnReceiveCompleted ¶
func (u *UdpService) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)
数据上传完成回调
func (*UdpService) CallOnReplyCompleted ¶ added in v1.2.0
func (u *UdpService) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, err error)
下发后回调
func (*UdpService) GetAcceptQueueCount ¶ added in v1.4.1
func (u *UdpService) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)
获取连接接入队列剩余数
func (*UdpService) GetConn ¶
func (u *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)
func (*UdpService) GetRecInfo ¶ added in v1.4.1
func (u *UdpService) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*UdpService) GetRepInfo ¶ added in v1.4.1
func (u *UdpService) GetRepInfo() (count, byteSize, errCount uint64)
下行当前处理的包总数(处理后),总大小(字节),异常数
func (*UdpService) GetStartTime ¶ added in v1.4.1
func (u *UdpService) GetStartTime() time.Time
获取连接启动时间
func (*UdpService) GetTotalQueueCount ¶ added in v1.2.0
func (u *UdpService) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, replyCount int64, replyTotalCount, replyOutTimeCount uint64)
获取队列剩余数
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) SetOnReceiveCompleted ¶
func (u *UdpService) SetOnReceiveCompleted(hookFunc func(netInterface.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*UdpService) SetOnReplyCompleted ¶ added in v1.2.0
func (u *UdpService) SetOnReplyCompleted(hookFunc func(netInterface.IConnection, []byte, interface{}, bool, error))