Documentation ¶
Index ¶
- func NewConnManager() netConn.IConnManager
- func NewConnection(server *Service, conn net.Conn, connId uint64, ...) netConn.IConnection
- func NewService(config *Config) netConn.IService
- func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, ...) netConn.IConnection
- func NewUdpService(config *Config) netConn.IService
- type Config
- type ConnManager
- func (connMgr *ConnManager) Add(conn netConn.IConnection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) Get(connID uint64) (netConn.IConnection, bool)
- func (connMgr *ConnManager) GetOvertimeConn(overtimeSecond float64) []netConn.IConnection
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Remove(conn netConn.IConnection)
- type Connection
- func (c *Connection) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
- func (c *Connection) GetBytesCache() *bytes.Buffer
- func (c *Connection) GetConnId() uint64
- func (c *Connection) GetHeartTime() time.Time
- func (c *Connection) GetLocalAddr() net.Addr
- func (c *Connection) GetNetConn() interface{}
- func (c *Connection) GetPackCount() int64
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetReceiver() []netConn.IReceiver
- func (c *Connection) GetRemoteAddr() net.Addr
- 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 RequestTask
- type ResponseTask
- type Service
- func (s *Service) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
- func (s *Service) CallOnConnStart(conn netConn.IConnection)
- func (s *Service) CallOnConnStop(conn netConn.IConnection)
- func (s *Service) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)
- func (s *Service) CallOnReplyCompleted(conn netConn.IConnection, data []byte, param interface{}, ok bool, err error)
- func (s *Service) GetConn(connId uint64) (netConn.IConnection, bool)
- func (s *Service) GetConnId() uint64
- func (s *Service) GetConnMgr() netConn.IConnManager
- func (s *Service) GetTotalQueueCount() (receiveCount int32, replyCount int32)
- func (s *Service) SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver)
- func (s *Service) SetLogHandle(hookFunc func(level netConn.ErrLevel, msg string))
- func (s *Service) SetOnConnStart(hookFunc func(netConn.IConnection))
- func (s *Service) SetOnConnStop(hookFunc func(netConn.IConnection))
- func (s *Service) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))
- func (s *Service) SetOnReplyCompleted(hookFunc func(netConn.IConnection, []byte, interface{}, bool, error))
- func (s *Service) Start()
- func (s *Service) Stop()
- type UdpConnection
- func (c *UdpConnection) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
- func (c *UdpConnection) GetBytesCache() *bytes.Buffer
- func (c *UdpConnection) GetConnId() uint64
- func (c *UdpConnection) GetHeartTime() time.Time
- func (c *UdpConnection) GetLocalAddr() net.Addr
- func (c *UdpConnection) GetNetConn() interface{}
- func (c *UdpConnection) GetPackCount() int64
- func (c *UdpConnection) GetProperty(key string) (interface{}, error)
- func (c *UdpConnection) GetRemoteAddr() net.Addr
- func (c *UdpConnection) OnCompleted(data []byte, offset int, count int)
- func (c *UdpConnection) OnReceiveCompleted(data []byte)
- func (c *UdpConnection) RemoveProperty(key string)
- func (c *UdpConnection) SendData(data []byte) error
- func (c *UdpConnection) SendDataCall(data []byte, param interface{}, ...) error
- func (c *UdpConnection) SetProperty(key string, value interface{})
- func (c *UdpConnection) Start()
- func (c *UdpConnection) Stop()
- type UdpRequestTask
- type UdpResponseTask
- type UdpService
- func (s *UdpService) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
- func (s *UdpService) CallOnConnStart(conn netConn.IConnection)
- func (s *UdpService) CallOnConnStop(conn netConn.IConnection)
- func (s *UdpService) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)
- func (s *UdpService) CallOnReplyCompleted(conn netConn.IConnection, data []byte, param interface{}, ok bool, err error)
- func (s *UdpService) GetConn(connId uint64) (netConn.IConnection, bool)
- func (s *UdpService) GetConnId() uint64
- func (s *UdpService) GetConnMgr() netConn.IConnManager
- func (s *UdpService) GetTotalQueueCount() (receiveCount int32, replyCount int32)
- func (s *UdpService) SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver)
- func (s *UdpService) SetLogHandle(hookFunc func(level netConn.ErrLevel, msg string))
- func (s *UdpService) SetOnConnStart(hookFunc func(netConn.IConnection))
- func (s *UdpService) SetOnConnStop(hookFunc func(netConn.IConnection))
- func (s *UdpService) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))
- func (s *UdpService) SetOnReplyCompleted(hookFunc func(netConn.IConnection, []byte, interface{}, bool, error))
- func (s *UdpService) Start()
- func (s *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 util.ITaskWorkerPool, replyHandle util.ITaskWorkerPool, config *Config) netConn.IConnection
创建连接的方法
func NewUdpConnection ¶
func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, receiveHandler util.ITaskWorkerPool, replyHandle util.ITaskWorkerPool, config *Config) netConn.IConnection
Udp连接
Types ¶
type Config ¶
type Config struct { Network string //网络:tcp,udp AddrAry []string //监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...] ReceiveWorkerSize uint //(上行处理)工作池中工作线程个数 ReceiveTaskQueueSize uint //(上行处理)单个工作队列缓存任务大小 ReplyWorkerSize uint //(下行处理)工作池中工作线程个数 ReplyTaskQueueSize uint //(下行处理)单个工作队列缓存任务大小 BufferSize uint //缓存尺寸(字节) BufferCount uint //缓存池缓存大小 BytesCacheSize uint //分包缓存大小(TCP必填,UDP不需要填写) SendOutTime time.Duration //下行超时时间(秒) }
配置
func DefaultConfig ¶ added in v1.2.0
默认配置
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
连接管理模块
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint64) (netConn.IConnection, bool)
利用ConnID获取链接
func (*ConnManager) GetOvertimeConn ¶ added in v1.1.1
func (connMgr *ConnManager) GetOvertimeConn(overtimeSecond float64) []netConn.IConnection
获取超时连接(overtimeSecond 秒)
type Connection ¶
type Connection struct { Server *Service //当前conn属于哪个server,在conn初始化的时候添加即可 Conn net.Conn //当前连接的socket 套接字 ConnId uint64 //当前连接的ID 也可以称作为SessionID,ID全局唯一 HeartTime time.Time //心跳时间 Receiver []netConn.IReceiver //分包器 PackCount int64 //包个数 // contains filtered or unexported fields }
连接结构体
func (*Connection) CallLogHandle ¶ added in v1.2.0
func (c *Connection) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
调用异常处理
func (*Connection) GetHeartTime ¶ added in v1.1.1
func (c *Connection) GetHeartTime() time.Time
获取心跳时间
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) 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(netConn.IConnection, bool, interface{}, error)) error
直接将Message数据发送数据给远程的TCP客户端(带参数和回调)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type RequestTask ¶ added in v1.2.0
type RequestTask struct {
// contains filtered or unexported fields
}
客户端请求内容
type ResponseTask ¶ added in v1.2.0
type ResponseTask struct {
// contains filtered or unexported fields
}
发送数据TCP
type Service ¶
type Service struct { ConnId uint64 //客户端id ConnMgr netConn.IConnManager //当前Server的链接管理器 CreateReceiver func(conn netConn.IConnection, data []byte) []netConn.IReceiver //数据分包 BufferPool *util.BufferPool //缓存管理器 // contains filtered or unexported fields }
IServer 接口实现,定义一个Server服务类
func (*Service) CallLogHandle ¶ added in v1.2.0
错误消息处理
func (*Service) CallOnConnStart ¶
func (s *Service) CallOnConnStart(conn netConn.IConnection)
调用连接OnConnStart Hook函数
func (*Service) CallOnConnStop ¶
func (s *Service) CallOnConnStop(conn netConn.IConnection)
调用连接OnConnStop Hook函数
func (*Service) CallOnReceiveCompleted ¶
func (s *Service) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)
数据上传完成回调
func (*Service) CallOnReplyCompleted ¶ added in v1.2.0
func (*Service) GetTotalQueueCount ¶ added in v1.2.0
获取队列剩余数
func (*Service) SetCreateReceiver ¶
设置创建分包策略方法
func (*Service) SetLogHandle ¶ added in v1.2.0
func (*Service) SetOnConnStart ¶
func (s *Service) SetOnConnStart(hookFunc func(netConn.IConnection))
设置该Server的连接创建时Hook函数
func (*Service) SetOnConnStop ¶
func (s *Service) SetOnConnStop(hookFunc func(netConn.IConnection))
设置该Server的连接断开时的Hook函数
func (*Service) SetOnReceiveCompleted ¶
func (s *Service) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*Service) SetOnReplyCompleted ¶ added in v1.2.0
type UdpConnection ¶
type UdpConnection struct { Server *UdpService //当前conn属于哪个server,在conn初始化的时候添加即可 Conn *net.UDPConn //当前连接的socket 套接字 ConnId uint64 //当前连接的ID 也可以称作为SessionID,ID全局唯一 RemoteAddr net.Addr //客户端地址 PackCount int64 //包个数 HeartTime time.Time //心跳时间 // contains filtered or unexported fields }
func (*UdpConnection) CallLogHandle ¶ added in v1.2.0
func (c *UdpConnection) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
调用异常处理
func (*UdpConnection) GetHeartTime ¶ added in v1.1.1
func (c *UdpConnection) GetHeartTime() time.Time
获取心跳时间
func (*UdpConnection) GetLocalAddr ¶ added in v1.2.2
func (c *UdpConnection) GetLocalAddr() net.Addr
获取本地地址信息
func (*UdpConnection) GetNetConn ¶ added in v1.2.2
func (c *UdpConnection) GetNetConn() interface{}
获取网络连接
func (*UdpConnection) GetProperty ¶
func (c *UdpConnection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*UdpConnection) OnCompleted ¶
func (c *UdpConnection) OnCompleted(data []byte, offset int, count int)
数据上次一包(未分包开始处理不确定是否完成)
func (*UdpConnection) OnReceiveCompleted ¶
func (c *UdpConnection) OnReceiveCompleted(data []byte)
数据上传完整的一包处理
func (*UdpConnection) SendDataCall ¶
func (c *UdpConnection) SendDataCall(data []byte, param interface{}, callFunc func(netConn.IConnection, bool, interface{}, error)) error
发送消息到客户端带回调
func (*UdpConnection) SetProperty ¶
func (c *UdpConnection) SetProperty(key string, value interface{})
设置链接属性
type UdpRequestTask ¶ added in v1.2.0
type UdpRequestTask struct {
// contains filtered or unexported fields
}
func (*UdpRequestTask) GetConnection ¶ added in v1.2.0
func (r *UdpRequestTask) GetConnection() (netConn.IConnection, bool)
获取请求连接信息
func (*UdpRequestTask) GetTaskId ¶ added in v1.2.0
func (r *UdpRequestTask) GetTaskId() uint64
获取连接id
type UdpResponseTask ¶ added in v1.2.0
type UdpResponseTask struct {
// contains filtered or unexported fields
}
Udp响应
func (*UdpResponseTask) GetTaskId ¶ added in v1.2.0
func (s *UdpResponseTask) GetTaskId() uint64
获取连接ID
type UdpService ¶
type UdpService struct { ConnId uint64 //客户端id ConnMgr netConn.IConnManager //当前Server的链接管理器 CreateReceiver func(conn netConn.IConnection, data []byte) []netConn.IReceiver //数据分包 BufferPool *util.BufferPool //缓存管理器 ConnectionsMap sync.Map //连接地址映射 // contains filtered or unexported fields }
IServer 接口实现,定义一个Server服务类
func (*UdpService) CallLogHandle ¶ added in v1.2.0
func (s *UdpService) CallLogHandle(level netConn.ErrLevel, msgAry ...interface{})
错误消息处理
func (*UdpService) CallOnConnStart ¶
func (s *UdpService) CallOnConnStart(conn netConn.IConnection)
调用连接OnConnStart Hook函数
func (*UdpService) CallOnConnStop ¶
func (s *UdpService) CallOnConnStop(conn netConn.IConnection)
调用连接OnConnStop Hook函数
func (*UdpService) CallOnReceiveCompleted ¶
func (s *UdpService) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)
数据上传完成回调
func (*UdpService) CallOnReplyCompleted ¶ added in v1.2.0
func (s *UdpService) CallOnReplyCompleted(conn netConn.IConnection, data []byte, param interface{}, ok bool, err error)
func (*UdpService) GetConn ¶
func (s *UdpService) GetConn(connId uint64) (netConn.IConnection, bool)
func (*UdpService) GetTotalQueueCount ¶ added in v1.2.0
func (s *UdpService) GetTotalQueueCount() (receiveCount int32, replyCount int32)
获取队列剩余数
func (*UdpService) SetCreateReceiver ¶
func (s *UdpService) SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver)
设置创建分包策略方法
func (*UdpService) SetLogHandle ¶ added in v1.2.0
func (s *UdpService) SetLogHandle(hookFunc func(level netConn.ErrLevel, msg string))
func (*UdpService) SetOnConnStart ¶
func (s *UdpService) SetOnConnStart(hookFunc func(netConn.IConnection))
设置该Server的连接创建时Hook函数
func (*UdpService) SetOnConnStop ¶
func (s *UdpService) SetOnConnStop(hookFunc func(netConn.IConnection))
设置该Server的连接断开时的Hook函数
func (*UdpService) SetOnReceiveCompleted ¶
func (s *UdpService) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))
数据上传完成处理函数[分包后]
func (*UdpService) SetOnReplyCompleted ¶ added in v1.2.0
func (s *UdpService) SetOnReplyCompleted(hookFunc func(netConn.IConnection, []byte, interface{}, bool, error))