netService

package
v1.3.13 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnManager

func NewConnManager() netInterface.IConnManager

NewConnManager 实例化管理

func NewService

func NewService(config *Config) netInterface.IService

NewService 初始化

Types

type Config

type Config struct {
	Scheme              string              //网络:ws,wss
	AddrAry             []string            //监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...]
	PathAry             []string            //监听路径
	ReplyWorkerSize     uint                //(下行处理)工作池中工作线程个数,必须2的N次方
	ReplyTaskQueueSize  uint                //(下行处理)单个工作队列缓存任务大小
	AcceptWorkerSize    uint                //(连接接入处理)工作池中工作线程个数,必须2的N次方
	AcceptTaskQueueSize uint                //(连接接入处理)单个工作队列缓存任务大小
	SendOutTime         time.Duration       //下行超时时间(秒)
	CertFile            string              //TLS安全连接文件【wss使用】
	KeyFile             string              //TLS安全连接key【wss使用】
	OverflowDiscard     bool                //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】
	Upgraded            *websocket.Upgrader //协议升级器
	KeepTime            time.Duration       //保持时间,(注:服务主要是是否能读取数据确认连接是否有存在必要)
}

Config 配置

func DefaultConfig

func DefaultConfig(scheme string, addrAry []string, pathAry []string, upgraded *websocket.Upgrader) *Config

DefaultConfig 默认配置

type ConnManager

type ConnManager struct {
	// contains filtered or unexported fields
}

ConnManager 连接管理模块

func (*ConnManager) Add

func (c *ConnManager) Add(conn netInterface.IConnection)

Add 添加链接[新连接处理]

func (*ConnManager) ClearConn

func (c *ConnManager) ClearConn()

ClearConn 清除并停止所有连接

func (*ConnManager) Count

func (c *ConnManager) Count() int32

Count 获取个数

func (*ConnManager) Get

func (c *ConnManager) Get(connId uint64) (netInterface.IConnection, bool)

Get 利用ConnID获取链接

func (*ConnManager) Range

func (c *ConnManager) Range(hFunc func(connId uint64, value netInterface.IConnection) bool)

Range 遍历连接

func (*ConnManager) Remove

func (c *ConnManager) Remove(conn netInterface.IConnection)

Remove 删除连接

func (*ConnManager) RemoveById added in v1.3.4

func (c *ConnManager) RemoveById(connId uint64)

RemoveById 删除连接

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection 连接

func NewConnection

func NewConnection(server *Service, conn *websocket.Conn, connId uint64, request *http.Request) *Connection

NewConnection 初始化连接方法

func (*Connection) CallLogHandle

func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 调用异常处理

func (*Connection) GetConnId

func (c *Connection) GetConnId() uint64

GetConnId 获取客户端ID

func (*Connection) GetHeartTime

func (c *Connection) GetHeartTime() time.Time

GetHeartTime 连接最后一次接收数据时间

func (*Connection) GetIsClosed

func (c *Connection) GetIsClosed() bool

GetIsClosed 获取的状态[脏读][ture:关闭状态,false:未关闭]

func (*Connection) GetLocalAddr

func (c *Connection) GetLocalAddr() net.Addr

GetLocalAddr 获取本地地址

func (*Connection) GetNetConn

func (c *Connection) GetNetConn() interface{}

GetNetConn 获取连接

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)

GetProperty 获取连接属性

func (*Connection) GetPropertyKeys added in v1.3.1

func (c *Connection) GetPropertyKeys() []string

GetPropertyKeys 获取所有属性key

func (*Connection) GetRecInfo

func (c *Connection) GetRecInfo() (count, byteSize uint64)

GetRecInfo 上行当前处理的包总数(处理前,1开始),总大小(字节)

func (*Connection) GetRemoteAddr

func (c *Connection) GetRemoteAddr() net.Addr

GetRemoteAddr 获取远程客户端地址信息

func (*Connection) GetRepInfo

func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)

GetRepInfo 下行当前处理的包总数(处理后),总大小(字节)

func (*Connection) GetRequest added in v1.3.6

func (c *Connection) GetRequest() *http.Request

GetRequest 获取请求体

func (*Connection) GetSendTime added in v1.3.13

func (c *Connection) GetSendTime() time.Time

GetSendTime 连接最后一次发送数据时间

func (*Connection) GetStartTime

func (c *Connection) GetStartTime() time.Time

GetStartTime 连接建立时间

func (*Connection) Incr added in v1.3.10

func (c *Connection) Incr(val int64) int64

Incr 连接提供给业务作为流水号使用,循环累加,(val 为正数为递增,val为负数为递减,val为0则获取值)

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

RemoveProperty 移除设置属性

func (*Connection) SendData

func (c *Connection) SendData(msgType int, data []byte, cmdCode string) error

SendData 发送数据给远程的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

SendDataCall 发送数据给远程的TCP客户端(带参数和回调)消息类型 1.TextMessage(文本) 2、BinaryMessage(二进制)

func (*Connection) SetProperty

func (c *Connection) SetProperty(key string, value interface{})

SetProperty 设置连接属性

func (*Connection) Start

func (c *Connection) Start()

Start 启动连接,让当前连接,开始工作 [只会调用一次]

func (*Connection) Stop

func (c *Connection) Stop()

Stop 停止连接,结束当前连接工作

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
}

Service 服务

func (*Service) CallLogHandle

func (s *Service) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

CallLogHandle 错误消息处理

func (*Service) CallOnConnStart

func (s *Service) CallOnConnStart(conn netInterface.IConnection)

CallOnConnStart 调用连接之前

func (*Service) CallOnConnStop

func (s *Service) CallOnConnStop(conn netInterface.IConnection)

CallOnConnStop 调用关闭之前

func (*Service) CallOnOneReceive added in v1.3.1

func (s *Service) CallOnOneReceive(conn netInterface.IConnection, msgType int, data []byte)

CallOnOneReceive [第一包]数据上传完成回调

func (*Service) CallOnReceive added in v1.3.1

func (s *Service) CallOnReceive(conn netInterface.IConnection, msgType int, data []byte)

CallOnReceive 数据上传完成回调

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)

CallOnReply 下发后回调

func (*Service) GetConn

func (s *Service) GetConn(connId uint64) (netInterface.IConnection, bool)

GetConn 获取连接

func (*Service) GetConnMgr

func (s *Service) GetConnMgr() netInterface.IConnManager

GetConnMgr 得到链接管理

func (*Service) GetIsStart added in v1.3.12

func (s *Service) GetIsStart() bool

GetIsStart 获取是否启动[true 启动,false 未启动]

func (*Service) GetStartTime

func (s *Service) GetStartTime() time.Time

GetStartTime 获取连接启动时间

func (*Service) SetLogHandle

func (s *Service) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))

SetLogHandle 设置日志处理

func (*Service) SetOnConnAuth added in v1.3.1

func (s *Service) SetOnConnAuth(hookStart func(conn netInterface.IConnection, w http.ResponseWriter, r *http.Request) bool)

SetOnConnAuth 连接之前回调

func (*Service) SetOnConnStart

func (s *Service) SetOnConnStart(hookStart func(conn netInterface.IConnection))

SetOnConnStart 连接完成回调

func (*Service) SetOnConnStop

func (s *Service) SetOnConnStop(hookStop func(conn netInterface.IConnection))

SetOnConnStop 关闭之前回调

func (*Service) SetOnOneReceive added in v1.3.1

func (s *Service) SetOnOneReceive(hookFunc func(netInterface.IConnection, int, []byte))

SetOnOneReceive 【第一包数据】数据上传完成处理函数[分包后]

func (*Service) SetOnReceive added in v1.3.1

func (s *Service) SetOnReceive(hookFunc func(netInterface.IConnection, int, []byte))

SetOnReceive 数据上传完成处理函数[分包后]

func (*Service) SetOnReply added in v1.3.1

func (s *Service) SetOnReply(hookFunc func(netInterface.IConnection, int, []byte, bool, string, interface{}, error))

SetOnReply 数据回复完成后处理函数

func (*Service) Start

func (s *Service) Start()

Start 启动

func (*Service) Stop

func (s *Service) Stop()

Stop 停止

func (*Service) ToMap added in v1.3.13

func (s *Service) ToMap() map[string]int64

ToMap 获取日志

Jump to

Keyboard shortcuts

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