netInterface

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MultiSizeBufferPool = pools.NewBufferPoolMany(128, 65536, 2)

多种尺寸缓存池

Functions

This section is empty.

Types

type ErrLevel

type ErrLevel int

错误级别

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

type IConnManager

type IConnManager interface {
	Add(conn IConnection)                                 //添加链接
	Remove(conn IConnection)                              //删除连接
	Get(connID uint64) (IConnection, bool)                //利用ConnID获取链接
	Count() int                                           //连接数
	Range(hFunc func(key uint64, value IConnection) bool) //遍历
	ClearConn()                                           //删除并停止所有链接
}

连接管理接口

type IConnection

type IConnection interface {
	GetNetConn() interface{}                                                                                                                 //获取连接(udp获取到的是监听的连接,tcp获取的是真正的客户端连接)
	GetConnId() uint64                                                                                                                       //获取客户端ID
	GetRemoteAddr() net.Addr                                                                                                                 //获取远程客户端地址信息
	GetLocalAddr() net.Addr                                                                                                                  //获取本地地址
	GetHeartTime() time.Time                                                                                                                 //心跳时间
	SendData(data []byte, cmdCode string) error                                                                                              //发送消息到客户端: data 下发数据,cmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。]
	SendDataCall(data []byte, cmdCode string, param interface{}, callFunc func(IConnection, []byte, bool, string, interface{}, error)) error //发送消息到客户端带回调:data 下发数据 param    下发需要回调携带参数 cmdCode  指令标识[如: rep 普通回复, cmd 用户操作下发 。。] callFunc 下发后回调函数
	SetProperty(key string, value interface{})                                                                                               //设置链接属性
	GetProperty(key string) (interface{}, error)                                                                                             //获取链接属性
	RemoveProperty(key string)                                                                                                               //移除链接属性
	GetRecInfo() (count, byteSize uint64)                                                                                                    //上行当前处理的包总数(处理前,1开始),总大小(字节)
	GetRepInfo() (count, byteSize, errCount uint64)                                                                                          //下行当前处理的包总数(处理后),总大小(字节)
	GetStartTime() time.Time                                                                                                                 //连接启动时间
	CallLogHandle(level ErrLevel, msgAry ...interface{})                                                                                     //设置内部异常抛出处理
	Start()                                                                                                                                  //启动连接,让当前连接开始工作
	Stop()                                                                                                                                   //停止连接,结束当前连接状态
	GetIsClosed() bool                                                                                                                       //获取的状态(ture:关闭状态,false:未关闭)
	OnCompleted(data []byte, count int)                                                                                                      //接收到一次数据(未分包开始处理不确定是否完成)
	OnReceiveCompleted(data []byte)                                                                                                          //数据上传一包完成
}

连接的接口

type IReceiver

type IReceiver interface {
	GetHeadLen() int                                        //获取分包所需包头长度
	CanHandle(conn IConnection, buffer []byte) bool         //是否能处理
	Receiver(conn IConnection, buffer []byte) ([]byte, int) //返回数据包,处理到的位置
}

分包器

type IService

type IService interface {
	Start()                                                                                   //启动服务器方法
	Stop()                                                                                    //停止服务器方法
	GetConnMgr() IConnManager                                                                 //得到链接管理
	GetConn(connId uint64) (IConnection, bool)                                                //获取连接
	SetLogHandle(func(level ErrLevel, msg ...interface{}))                                    //设置内部异常抛出处理
	SetCreateReceiver(hookFunc func(IConnection, []byte) []IReceiver)                         //设置分包处理方法(支持TCP,UDP都是上传完整数据包不需要分包)
	SetOnConnStart(hookFunc func(IConnection))                                                //设置连接结束处理方法
	SetOnConnStop(hookFunc func(IConnection))                                                 //设置连接开始处理方法
	SetOnReceiveCompleted(hookFunc func(IConnection, []byte))                                 //连接上传一包完整数据(连接,上行数据)
	SetOnReplyCompleted(hookFunc func(IConnection, []byte, bool, string, interface{}, error)) //设置下发回调(连接,下发数据,下发数据时带的参数,是否成功,异常信息)
	GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64,
		replyCount int64, replyTotalCount, replyOutTimeCount uint64) //获取处理队列和下发队列剩余数
	GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64) //获取连接接入队列剩余数[TCP才有]
	GetRecInfo() (count, byteSize uint64)                                //上行当前处理的包总数(处理前,1开始),总大小(字节)
	GetRepInfo() (count, byteSize, errCount uint64)                      ////下行当前处理的包总数(处理后),总大小(字节),异常数
	GetStartTime() time.Time                                             //获取连接启动时间
}

定义服务器接口

Jump to

Keyboard shortcuts

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