netConn

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IConnManager

type IConnManager interface {
	Add(conn IConnection)                  //添加链接
	Remove(conn IConnection)               //删除连接
	Get(connID uint64) (IConnection, bool) //利用ConnID获取链接
	ClearConn()                            //删除并停止所有链接
}

连接管理接口

type IConnection

type IConnection interface {
	GetConnId() uint64       //获取客户端ID
	GetRemoteAddr() net.Addr //获取远程客户端地址信息

	SendData(data []byte) error                                                                              //发送消息到客户端
	SendDataCall(data []byte, param interface{}, callFunc func(IConnection, bool, interface{}, error)) error //发送消息到客户端带回调

	SetProperty(key string, value interface{})   //设置链接属性
	GetProperty(key string) (interface{}, error) //获取链接属性
	RemoveProperty(key string)                   //移除链接属性

	GetPackCount() int64          //当前包数
	GetBytesCache() *bytes.Buffer //分包内容数据缓存

	OnCompleted(data []byte, offset int, count int) //数据上次一包(未分包开始处理不确定是否完成)
	OnReceiveCompleted(data []byte)                 //数据上传完整的一包处理

	Start() //启动连接,让当前连接开始工作
	Stop()  //停止连接,结束当前连接状态M
}

连接的接口

type IMsgHandle

type IMsgHandle interface {
	StartWorkerPool()                    //启动worker工作池
	StopWorkerPool()                     //停止worker工作池
	SendMsgToTaskQueue(request IRequest) //将消息交给TaskQueue,由worker进行处理
}

消息处理池接口

type IReceiver

type IReceiver interface {
	IsMeHandle(conn IConnection, buffer []byte) (isMe bool)       //是否处理
	Receiver(conn IConnection, buffer []byte) ([]byte, int, bool) //分包处理[处理一包后跳出]
}

分包器

type IRequest

type IRequest interface {
	GetConnection() IConnection //获取请求连接信息
	GetData() []byte            //获取请求消息的数据
	GetCount() int              //获取消息长度
}

客户端请求的内容接口

type IService

type IService interface {
	Start()                                                           //启动服务器方法
	Stop()                                                            //停止服务器方法
	GetConnMgr() IConnManager                                         //得到链接管理
	GetConn(connId uint64) (IConnection, bool)                        //获取连接
	SetErrorHandle(func(level string, msg string))                    //设置内部异常抛出处理
	SetCreateReceiver(hookFunc func(IConnection, []byte) []IReceiver) //设置分包处理方法
	SetOnConnStart(hookFunc func(IConnection))                        //设置连接结束处理方法
	SetOnConnStop(hookFunc func(IConnection))                         //设置连接开始处理方法
	SetOnReceiveCompleted(hookFunc func(IConnection, []byte))         //连接上传一包完整数据
}

定义服务器接口

Jump to

Keyboard shortcuts

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