netInterface

package
v1.3.11 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AcceptTask  TaskTypeCode = 1 //连接任务
	ReceiveTask TaskTypeCode = 2 //上行分包任务[UDP不需要分包,使用这个任务池处理数据]
	ReplyTask   TaskTypeCode = 4 //下行任务
	TaskOutTime TaskErrCode  = 0 //超时
	TaskErr     TaskErrCode  = 1 //错误
)

Functions

This section is empty.

Types

type ErrLevel

type ErrLevel int

ErrLevel 错误级别

const (
	Fatal ErrLevel = 0 //致命
	Error ErrLevel = 1 //错误
	Warn  ErrLevel = 2 //警告
	Info  ErrLevel = 3 //一般信息
)

type IConnManager

type IConnManager interface {
	Add(conn IConnection)                                    //添加链接
	Remove(conn IConnection)                                 //移除连接
	RemoveById(connId uint64)                                //移除连接
	Get(connId uint64) (IConnection, bool)                   //利用ConnID获取链接
	Count() int                                              //获取个数[内部遍历整个map,调用频率控制在'大于5秒']
	Range(hFunc func(connId uint64, value IConnection) bool) //遍历
	ClearConn()                                              //删除并停止所有链接
}

IConnManager

连接管理接口

type IConnection

type IConnection interface {
	GetNetConn() interface{} //获取连接
	GetNetwork() string      //获取网络类型[ws,wss]
	GetConnId() uint64       //获取客户端ID
	GetRemoteAddr() net.Addr //获取远程客户端地址信息
	GetLocalAddr() net.Addr  //获取本地地址
	GetHeartTime() time.Time //心跳时间
	// SendData 发送消息到客户端:消息类型 1.TextMessage(文本) 2、BinaryMessage(二进制) cmdCode  指令标识[如: rep 普通回复, cmd 用户操作下发 。。]
	SendData(msgType int, data []byte, cmdCode string) error
	// SendDataCall 发送消息到客户端带回调:消息类型 1.TextMessage(文本) 2、BinaryMessage(二进制) cmdCode  指令标识[如: rep 普通回复, cmd 用户操作下发 。。]
	SendDataCall(msgType int, data []byte, cmdCode string, param interface{}, callFunc func(IConnection, int, []byte, bool, string, interface{}, error)) error
	SetProperty(key string, value interface{})           //设置链接属性
	GetProperty(key string) (interface{}, error)         //获取链接属性
	RemoveProperty(key string)                           //移除链接属性
	GetPropertyKeys() []string                           //获取所有属性key
	GetRecInfo() (count, byteSize uint64)                //上行当前处理的包总数(处理前,1开始),总大小(字节)
	GetRepInfo() (count, byteSize, errCount uint64)      //下行当前处理的包总数(处理后),总大小(字节)
	CallLogHandle(level ErrLevel, msgAry ...interface{}) //设置内部异常抛出处理
	Start()                                              //启动连接,让当前连接开始工作
	Stop()                                               //停止连接,结束当前连接状态
	GetIsClosed() bool                                   //获取的状态(ture:关闭状态,false:未关闭)
	GetRequest() *http.Request                           //获取请求体
	Incr(val int64) int64                                //连接提供给业务作为流水号使用,循环累加,(val 为正数为递增,val为负数为递减,val为0则获取值)
}

IConnection 连接的接口

type IService

type IService interface {
	Start()                                                                                                  //启动服务器方法
	Stop()                                                                                                   //停止服务器方法
	GetConnMgr() IConnManager                                                                                //得到链接管理
	GetConn(connId uint64) (IConnection, bool)                                                               //获取连接
	SetLogHandle(func(level ErrLevel, msg ...interface{}))                                                   //设置内部异常抛出处理
	SetOnConnAuth(h func(conn IConnection, w http.ResponseWriter, r *http.Request) bool)                     //连接前验证
	SetOnConnStart(h func(IConnection))                                                                      //设置连接结束处理方法
	SetOnConnStop(h func(IConnection))                                                                       //设置连接开始处理方法
	SetOnOneReceive(h func(IConnection, int, []byte))                                                        //连接上传第一包完整数据(连接,上行数据)
	SetOnReceive(h func(IConnection, int, []byte))                                                           //连接上传一包完整数据(连接,上行数据)
	SetOnReply(h func(IConnection, int, []byte, bool, string, interface{}, error))                           //设置下发回调(连接,下发数据,下发数据时带的参数,是否成功,异常信息)
	SetRunTaskError(h func(conn IConnection, taskType TaskTypeCode, taskCode TaskErrCode, task interface{})) //设置处理上发或下行任务处理异常函数
	GetStartTime() time.Time                                                                                 //获取服务启动时间
	GetReceiveWorkerPool() pools.ITaskWorkerPool                                                             //消息处理模块(工作池)
	GetReplyWorkerPool() pools.ITaskWorkerPool                                                               //消息发送处理器(工作池)
	GetAcceptWorkerPool() pools.ITaskWorkerPool                                                              //连接接收处理器(工作池)
}

IService 定义服务器接口

type TaskErrCode added in v1.3.9

type TaskErrCode int

TaskErrCode 异常码

type TaskTypeCode added in v1.3.9

type TaskTypeCode int

TaskTypeCode 任务类型码

Jump to

Keyboard shortcuts

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