Documentation
¶
Index ¶
- Variables
- func NewConnManager() netInterface.IConnManager
- func NewService(config *Config) netInterface.IService
- type AcceptTask
- type AcceptTaskPool
- 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) GetRequest() *http.Request
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendData(msgType int, data []byte, cmdCode string) error
- func (c *Connection) SendDataCall(msgType int, data []byte, cmdCode string, param interface{}, ...) error
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) StartReader()
- func (c *Connection) Stop()
- type ReceiveTask
- type ReceiveTaskPool
- type ReplyTask
- type ReplyTaskPool
- 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) CallOnOneReceive(conn netInterface.IConnection, msgType int, data []byte)
- func (s *Service) CallOnReceive(conn netInterface.IConnection, msgType int, data []byte)
- func (s *Service) CallOnReply(conn netInterface.IConnection, msgType int, data []byte, ok bool, ...)
- func (s *Service) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)
- 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) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, ...)
- func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
- func (s *Service) SetOnConnAuth(...)
- func (s *Service) SetOnConnStart(hookStart func(conn netInterface.IConnection))
- func (s *Service) SetOnConnStop(hookStop func(conn netInterface.IConnection))
- func (s *Service) SetOnOneReceive(hookFunc func(netInterface.IConnection, int, []byte))
- func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, int, []byte))
- func (s *Service) SetOnReply(...)
- func (s *Service) Start()
- func (s *Service) Stop()
Constants ¶
This section is empty.
Variables ¶
var AcceptPool = NewAcceptTaskPool()
AcceptPool 数据回复池
var ReceivePool = NewReceiveTaskPool()
ReceivePool 数据处理池
var ReplyPool = NewReplyTaskPool()
ReplyPool 数据回复池
Functions ¶
Types ¶
type AcceptTask ¶
type AcceptTask struct { Conn *websocket.Conn //连接 ConnId uint64 //客户端ID Response http.ResponseWriter //响应 Request *http.Request //请求 Duration time.Duration //超时时间 OnAccept func(accept *AcceptTask) //接收到一次数据(未分包开始处理不确定是否完成) RunOutTime func(accept *AcceptTask) //超时回调 }
连接接入任务
func (*AcceptTask) GetDuration ¶ added in v1.3.3
func (a *AcceptTask) GetDuration() time.Duration
type AcceptTaskPool ¶ added in v1.3.6
type AcceptTaskPool struct {
// contains filtered or unexported fields
}
AcceptTaskPool 数据回复池
func NewAcceptTaskPool ¶ added in v1.3.6
func NewAcceptTaskPool() *AcceptTaskPool
NewAcceptTaskPool 实例化buffer
func (*AcceptTaskPool) Put ¶ added in v1.3.6
func (a *AcceptTaskPool) Put(acceptTask *AcceptTask)
Put 回收
type Config ¶
type Config struct { Scheme string //网络:ws,wss AddrAry []string //监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...] PathAry []string //监听路径 ReceiveWorkerSize uint //(上行处理)工作池中工作线程个数,,必须2的N次方 ReceiveTaskQueueSize uint //(上行处理)单个工作队列缓存任务大小 ReceiveOutTime time.Duration //(上行处理)处理任务超时时间 ,IsOutTime=true 时生效 ReplyWorkerSize uint //(下行处理)工作池中工作线程个数,必须2的N次方 ReplyTaskQueueSize uint //(下行处理)单个工作队列缓存任务大小 ReplyOutTime time.Duration //(下行处理)超时时间(完整任务) ,IsOutTime=true 时生效 AcceptWorkerSize uint //(连接接入处理)工作池中工作线程个数,必须2的N次方 AcceptTaskQueueSize uint //(连接接入处理)单个工作队列缓存任务大小 AcceptOutTime time.Duration //(连接接入处理)超时时间,IsOutTime=true 时生效 RBufferSize int //读缓存尺寸(字节) WBufferSize int //写缓存尺寸(字节) SendOutTime time.Duration //下行超时时间(秒) CertFile string //TLS安全连接文件【wss使用】 KeyFile string //TLS安全连接key【wss使用】 IsOutTime bool //是否需要支持超时 OverflowDiscard bool //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】 }
配置
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 ¶
func (c *ConnManager) Range(hFunc func(connId uint64, value netInterface.IConnection) bool)
遍历连接
func (*ConnManager) RemoveById ¶ added in v1.3.4
func (c *ConnManager) RemoveById(connId uint64)
删除连接
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
连接
func NewConnection ¶
func NewConnection(server *Service, conn *websocket.Conn, connId uint64, request *http.Request) *Connection
初始化连接方法
func (*Connection) CallLogHandle ¶
func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
调用异常处理
func (*Connection) GetIsClosed ¶
func (c *Connection) GetIsClosed() bool
GetIsClosed 获取的状态[脏读][ture:关闭状态,false:未关闭]
func (*Connection) GetNetwork ¶ added in v1.3.6
func (c *Connection) GetNetwork() string
GetNetwork 获取网络类型
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
获取连接属性
func (*Connection) GetPropertyKeys ¶ added in v1.3.1
func (c *Connection) GetPropertyKeys() []string
获取所有属性key
func (*Connection) GetRecInfo ¶
func (c *Connection) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*Connection) GetRepInfo ¶
func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
下行当前处理的包总数(处理后),总大小(字节)
func (*Connection) GetRequest ¶ added in v1.3.6
func (c *Connection) GetRequest() *http.Request
获取请求体
func (*Connection) SendData ¶
func (c *Connection) SendData(msgType int, data []byte, cmdCode string) error
直接将Message数据发送数据给远程的TCP客户端消息类型 1.TextMessage(文本) 2、BinaryMessage(二进制)
func (*Connection) SendDataCall ¶
func (c *Connection) SendDataCall(msgType int, data []byte, cmdCode string, param interface{}, callFunc func(netInterface.IConnection, int, []byte, bool, string, interface{}, error)) error
直接将Message数据发送数据给远程的TCP客户端(带参数和回调)消息类型 1.TextMessage(文本) 2、BinaryMessage(二进制)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置连接属性
type ReceiveTask ¶
type ReceiveTask struct { ConnId uint64 //连接ID Data []byte //客户端请求的数据 MsgType int //消息类型 Duration time.Duration //超时时间 OnCompleted func(receive *ReceiveTask) //完成回调 RunOutTime func(receive *ReceiveTask) //超时回调 }
ReceiveTask 客户端请求内容
func (*ReceiveTask) GetDuration ¶ added in v1.3.3
func (r *ReceiveTask) GetDuration() time.Duration
GetDuration 获取超时时间
type ReceiveTaskPool ¶ added in v1.3.6
type ReceiveTaskPool struct {
// contains filtered or unexported fields
}
ReceiveTaskPool 数据处理池
func NewReceiveTaskPool ¶ added in v1.3.6
func NewReceiveTaskPool() *ReceiveTaskPool
NewReceiveTaskPool 实例化buffer
func (*ReceiveTaskPool) Put ¶ added in v1.3.6
func (r *ReceiveTaskPool) Put(receiveTask *ReceiveTask)
Put 回收
type ReplyTask ¶
type ReplyTask struct { ConnId uint64 //连接id Data []byte //发送数据 MsgType int //消息类型 Param interface{} //参数 CmdCode string //业务指定指令码 Duration time.Duration //超时时间 CallFunc func(netInterface.IConnection, int, []byte, bool, string, interface{}, error) //回调方法 RunReplyTask func(replyTask *ReplyTask) //下发完成回调方法 RunOutTime func(replyTask *ReplyTask) //运行超时回调 }
ReplyTask 发送数据TCP
func (*ReplyTask) GetDuration ¶ added in v1.3.3
GetDuration 获取超时时间
type ReplyTaskPool ¶ added in v1.3.6
type ReplyTaskPool struct {
// contains filtered or unexported fields
}
ReplyTaskPool 数据回复池
func NewReplyTaskPool ¶ added in v1.3.6
func NewReplyTaskPool() *ReplyTaskPool
NewReplyTaskPool 实例化buffer
func (*ReplyTaskPool) Put ¶ added in v1.3.6
func (r *ReplyTaskPool) Put(receiveTask *ReplyTask)
Put 回收
type Service ¶
type Service struct { ConnMgr netInterface.IConnManager //连接属性 OnConnAuth func(netInterface.IConnection, http.ResponseWriter, *http.Request) bool //连接建立前验证(true:成功,false:失败,关闭连接) OnConnStart func(netInterface.IConnection) //连接完成回调 OnConnStop func(netInterface.IConnection) //关闭回调 AcceptHandle pools.ITaskWorkerPool //连接处理池 // contains filtered or unexported fields }
服务
func (*Service) CallLogHandle ¶
func (s *Service) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
错误消息处理
func (*Service) CallOnConnStart ¶
func (s *Service) CallOnConnStart(conn netInterface.IConnection)
调用连接之前
func (*Service) CallOnConnStop ¶
func (s *Service) CallOnConnStop(conn netInterface.IConnection)
调用关闭之前
func (*Service) CallOnOneReceive ¶ added in v1.3.1
func (s *Service) CallOnOneReceive(conn netInterface.IConnection, msgType int, data []byte)
[第一包]数据上传完成回调
func (*Service) CallOnReceive ¶ added in v1.3.1
func (s *Service) CallOnReceive(conn netInterface.IConnection, msgType int, data []byte)
数据上传完成回调
func (*Service) CallOnReply ¶ added in v1.3.1
func (s *Service) CallOnReply(conn netInterface.IConnection, msgType int, data []byte, ok bool, cmdCode string, param interface{}, err error)
下发后回调
func (*Service) GetAcceptQueueCount ¶
获取连接接入队列剩余数
func (*Service) GetAcceptWorkerPool ¶ added in v1.3.4
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.3.4
func (s *Service) GetReceiveWorkerPool() pools.ITaskWorkerPool
消息处理模块(工作池)
func (*Service) GetReplyWorkerPool ¶ added in v1.3.4
func (s *Service) GetReplyWorkerPool() pools.ITaskWorkerPool
消息发送处理器(工作池)
func (*Service) GetTotalQueueCount ¶
func (s *Service) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, replyCount int64, replyTotalCount, replyOutTimeCount uint64)
获取队列剩余数
func (*Service) SetLogHandle ¶
func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))
设置日志处理
func (*Service) SetOnConnAuth ¶ added in v1.3.1
func (s *Service) SetOnConnAuth(hookStart func(conn netInterface.IConnection, w http.ResponseWriter, r *http.Request) bool)
连接之前回调
func (*Service) SetOnConnStart ¶
func (s *Service) SetOnConnStart(hookStart func(conn netInterface.IConnection))
连接完成回调
func (*Service) SetOnConnStop ¶
func (s *Service) SetOnConnStop(hookStop func(conn netInterface.IConnection))
关闭之前回调
func (*Service) SetOnOneReceive ¶ added in v1.3.1
func (s *Service) SetOnOneReceive(hookFunc func(netInterface.IConnection, int, []byte))
【第一包数据】数据上传完成处理函数[分包后]
func (*Service) SetOnReceive ¶ added in v1.3.1
func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, int, []byte))
数据上传完成处理函数[分包后]
func (*Service) SetOnReply ¶ added in v1.3.1
func (s *Service) SetOnReply(hookFunc func(netInterface.IConnection, int, []byte, bool, string, interface{}, error))
数据回复完成后处理函数