netService

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnManager

func NewConnManager() netInterface.IConnManager

实例化管理

func NewConnection

func NewConnection(server *Service, conn net.Conn, connId uint64, receiveHandler pools.ITaskWorkerPool, replyHandle pools.ITaskWorkerPool, config *Config) netInterface.IConnection

创建连接的方法

func NewService

func NewService(config *Config) netInterface.IService

实例化TCP服务类

func NewUdpConnection

func NewUdpConnection(server *UdpService, conn *net.UDPConn, connId uint64, remoteAddr net.Addr, receiveHandler pools.ITaskWorkerPool, replyHandle pools.ITaskWorkerPool, config *Config) netInterface.IConnection

Udp连接

func NewUdpService

func NewUdpService(config *Config) netInterface.IService

创建UDP服务

Types

type AcceptTask added in v1.4.1

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

连接接入任务

func (*AcceptTask) CallOutTime added in v1.4.1

func (a *AcceptTask) CallOutTime()

超时回调

func (*AcceptTask) GetTaskId added in v1.4.1

func (a *AcceptTask) GetTaskId() uint64

获取连接id

func (*AcceptTask) RunTask added in v1.4.1

func (a *AcceptTask) RunTask() int

处理数据

type AddrConfig added in v1.5.0

type AddrConfig struct {
	Addr      string //地址端口:192.168.1.24:7018
	CertFile  string //server.crt 文件路径:TCP支持Tls
	KeyFile   string //server.key 文件路径:TCP支持Tls
	ClientCer string //配置客户端证书【加入证书会开启客户端验证】
	IsTls     bool   //是否TLS连接
}

Tls配置

type Config

type Config struct {
	Network              string        //网络:tcp,udp
	AddrAry              []*AddrConfig //[普通/Tls]监听地址和端口:绑定的IP加端口:["192.168.1.24:7018",...]
	ReceiveWorkerSize    uint          //(上行处理)工作池中工作线程个数
	ReceiveTaskQueueSize uint          //(上行处理)单个工作队列缓存任务大小
	ReceiveOutTime       time.Duration //(上行处理)处理任务超时时间 ,IsOutTime=true 时生效
	ReplyWorkerSize      uint          //(下行处理)工作池中工作线程个数
	ReplyTaskQueueSize   uint          //(下行处理)单个工作队列缓存任务大小
	ReplyOutTime         time.Duration //(下行处理)超时时间(完整任务) ,IsOutTime=true 时生效
	AcceptWorkerSize     uint          //(连接接入处理)工作池中工作线程个数[tcp使用]
	AcceptTaskQueueSize  uint          //(连接接入处理)单个工作队列缓存任务大小[tcp使用]
	AcceptOutTime        time.Duration //(连接接入处理)超时时间,IsOutTime=true 时生效
	BufferSize           uint          //缓存尺寸(字节)
	BytesCacheSize       uint          //分包缓存大小
	SendOutTime          time.Duration //(下行处理网络)超时时间
	IsOutTime            bool          //是否需要支持超时
}

配置

func DefaultConfig added in v1.2.0

func DefaultConfig(network string, addrAry []string) *Config

普通网络配置

func NewConfig added in v1.5.0

func NewConfig(network string, addrAry []*AddrConfig) *Config

普通、Tls 网络都支持配置

type ConnManager

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

连接管理模块

func (*ConnManager) Add

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

添加链接

func (*ConnManager) ClearConn

func (c *ConnManager) ClearConn()

清除并停止所有连接

func (*ConnManager) Count added in v1.4.1

func (c *ConnManager) Count() int

获取个数

func (*ConnManager) Get

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

利用ConnID获取链接

func (*ConnManager) Range added in v1.3.1

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

遍历连接

func (*ConnManager) Remove

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

删除连接

type Connection

type Connection struct {
	Receiver []netInterface.IReceiver //分包器
	// contains filtered or unexported fields
}

连接结构体

func (*Connection) CallLogHandle added in v1.2.0

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

调用异常处理

func (*Connection) GetBytesCache

func (c *Connection) GetBytesCache() *bytes.Buffer

获取分包缓存

func (*Connection) GetConnId

func (c *Connection) GetConnId() uint64

获取当前连接ID

func (*Connection) GetHeartTime added in v1.1.1

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

获取心跳时间

func (*Connection) GetIsClosed added in v1.4.1

func (c *Connection) GetIsClosed() bool

获取的状态(ture:关闭状态,false:未关闭)

func (*Connection) GetLocalAddr added in v1.2.2

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

获取本地地址信息

func (*Connection) GetNetConn

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

从当前连接获取原始的socket TCPConn

func (*Connection) GetProperty

func (c *Connection) GetProperty(key string) (interface{}, error)

获取链接属性

func (*Connection) GetRecInfo added in v1.4.1

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

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

func (*Connection) GetReceiver

func (c *Connection) GetReceiver() []netInterface.IReceiver

获取分包器

func (*Connection) GetRemoteAddr

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

获取远程客户端地址信息

func (*Connection) GetRepInfo added in v1.4.1

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

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

func (*Connection) GetStartTime added in v1.4.1

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

获取连接启动时间

func (*Connection) OnCompleted

func (c *Connection) OnCompleted(data []byte, offset int, count int)

数据上传处理

func (*Connection) OnReceiveCompleted

func (c *Connection) OnReceiveCompleted(data []byte)

数据上传了完整一包的回调

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

移除链接属性

func (*Connection) SendData

func (c *Connection) SendData(data []byte) error

直接将Message数据发送数据给远程的TCP客户端

func (*Connection) SendDataCall

func (c *Connection) SendDataCall(data []byte, param interface{}, callFunc func(netInterface.IConnection, bool, interface{}, error)) error

直接将Message数据发送数据给远程的TCP客户端(带参数和回调)

func (*Connection) SetProperty

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

设置链接属性

func (*Connection) Start

func (c *Connection) Start()

启动连接,让当前连接开始工作

func (*Connection) Stop

func (c *Connection) Stop()

停止连接,结束当前连接状态M

type ReceiveTask added in v1.4.1

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

客户端请求内容

func (*ReceiveTask) CallOutTime added in v1.4.1

func (r *ReceiveTask) CallOutTime()

任务超时

func (*ReceiveTask) GetTaskId added in v1.4.1

func (r *ReceiveTask) GetTaskId() uint64

获取连接id

func (*ReceiveTask) RunTask added in v1.4.1

func (r *ReceiveTask) RunTask() int

处理数据

type ReplyTask added in v1.4.1

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

发送数据TCP

func (*ReplyTask) CallOutTime added in v1.4.1

func (r *ReplyTask) CallOutTime()

任务超时

func (*ReplyTask) GetTaskId added in v1.4.1

func (r *ReplyTask) GetTaskId() uint64

获取连接ID

func (*ReplyTask) RunTask added in v1.4.1

func (r *ReplyTask) RunTask() int

运行

type Service

type Service struct {
	AcceptHandle pools.ITaskWorkerPool //连接处理池
	// contains filtered or unexported fields
}

IServer 接口实现,定义一个Server服务类

func (*Service) AddConnId added in v1.4.1

func (s *Service) AddConnId() uint64

累加并获取自增ID

func (*Service) CallLogHandle added in v1.2.0

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

错误消息处理

func (*Service) CallOnConnStart

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

调用连接OnConnStart Hook函数

func (*Service) CallOnConnStop

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

调用连接OnConnStop Hook函数

func (*Service) CallOnReceiveCompleted

func (s *Service) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)

数据上传完成回调

func (*Service) CallOnReplyCompleted added in v1.2.0

func (s *Service) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, err error)

下发后回调

func (*Service) GetAcceptQueueCount added in v1.4.1

func (s *Service) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)

获取连接接入队列剩余数

func (*Service) GetConn

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

获取连接

func (*Service) GetConnMgr

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

得到链接管理

func (*Service) GetRecInfo added in v1.4.1

func (s *Service) GetRecInfo() (count, byteSize uint64)

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

func (*Service) GetRepInfo added in v1.4.1

func (s *Service) GetRepInfo() (count, byteSize, errCount uint64)

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

func (*Service) GetStartTime added in v1.4.1

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

获取连接启动时间

func (*Service) GetTotalQueueCount added in v1.2.0

func (s *Service) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, replyCount int64, replyTotalCount, replyOutTimeCount uint64)

获取队列剩余数

func (*Service) SetCreateReceiver

func (s *Service) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)

设置创建分包策略方法

func (*Service) SetLogHandle added in v1.2.0

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

设置日志处理

func (*Service) SetOnConnStart

func (s *Service) SetOnConnStart(hookFunc func(netInterface.IConnection))

设置该Server的连接创建时Hook函数

func (*Service) SetOnConnStop

func (s *Service) SetOnConnStop(hookFunc func(netInterface.IConnection))

设置该Server的连接断开时的Hook函数

func (*Service) SetOnReceiveCompleted

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

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

func (*Service) SetOnReplyCompleted added in v1.2.0

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

func (*Service) Start

func (s *Service) Start()

开启网络服务

func (*Service) Stop

func (s *Service) Stop()

停止服务

type UdpConnection

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

func (*UdpConnection) CallLogHandle added in v1.2.0

func (u *UdpConnection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

调用异常处理

func (*UdpConnection) GetBytesCache

func (u *UdpConnection) GetBytesCache() *bytes.Buffer

获取缓存

func (*UdpConnection) GetConnId

func (u *UdpConnection) GetConnId() uint64

获取当前连接ID

func (*UdpConnection) GetHeartTime added in v1.1.1

func (u *UdpConnection) GetHeartTime() time.Time

获取心跳时间

func (*UdpConnection) GetIsClosed added in v1.4.1

func (u *UdpConnection) GetIsClosed() bool

获取的状态(ture:关闭状态,false:未关闭)

func (*UdpConnection) GetLocalAddr added in v1.2.2

func (u *UdpConnection) GetLocalAddr() net.Addr

获取本地地址信息

func (*UdpConnection) GetNetConn added in v1.2.2

func (u *UdpConnection) GetNetConn() interface{}

获取网络连接

func (*UdpConnection) GetProperty

func (u *UdpConnection) GetProperty(key string) (interface{}, error)

获取链接属性

func (*UdpConnection) GetRecInfo added in v1.4.1

func (u *UdpConnection) GetRecInfo() (count, byteSize uint64)

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

func (*UdpConnection) GetRecPackCount added in v1.4.1

func (u *UdpConnection) GetRecPackCount() uint64

获取上行当前处理的包总数(处理前,1开始)

func (*UdpConnection) GetRemoteAddr

func (u *UdpConnection) GetRemoteAddr() net.Addr

获取远程客户端地址信息

func (*UdpConnection) GetRepInfo added in v1.4.1

func (u *UdpConnection) GetRepInfo() (count, byteSize, errCount uint64)

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

func (*UdpConnection) GetStartTime added in v1.4.1

func (u *UdpConnection) GetStartTime() time.Time

获取连接启动时间

func (*UdpConnection) OnCompleted

func (u *UdpConnection) OnCompleted(data []byte, offset int, count int)

数据上次一包(未分包开始处理不确定是否完成)

func (*UdpConnection) OnReceiveCompleted

func (u *UdpConnection) OnReceiveCompleted(data []byte)

数据上传完整的一包处理

func (*UdpConnection) RemoveProperty

func (u *UdpConnection) RemoveProperty(key string)

移除链接属性

func (*UdpConnection) SendData

func (u *UdpConnection) SendData(data []byte) error

发送消息到客户端

func (*UdpConnection) SendDataCall

func (u *UdpConnection) SendDataCall(data []byte, param interface{}, callFunc func(netInterface.IConnection, bool, interface{}, error)) error

发送消息到客户端带回调

func (*UdpConnection) SetProperty

func (u *UdpConnection) SetProperty(key string, value interface{})

设置链接属性

func (*UdpConnection) Start

func (u *UdpConnection) Start()

启动连接,让当前连接开始工作

func (*UdpConnection) Stop

func (u *UdpConnection) Stop()

停止连接,结束当前连接状态M

type UdpReceiveTask added in v1.4.1

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

func (*UdpReceiveTask) CallOutTime added in v1.4.1

func (u *UdpReceiveTask) CallOutTime()

任务超时

func (*UdpReceiveTask) GetConnection added in v1.4.1

func (u *UdpReceiveTask) GetConnection() (netInterface.IConnection, bool)

获取请求连接信息

func (*UdpReceiveTask) GetTaskId added in v1.4.1

func (u *UdpReceiveTask) GetTaskId() uint64

获取连接id

func (*UdpReceiveTask) RunTask added in v1.4.1

func (u *UdpReceiveTask) RunTask() int

处理

type UdpReplyTask added in v1.4.1

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

Udp响应

func (*UdpReplyTask) CallOutTime added in v1.4.1

func (u *UdpReplyTask) CallOutTime()

任务超时

func (*UdpReplyTask) GetTaskId added in v1.4.1

func (u *UdpReplyTask) GetTaskId() uint64

获取连接ID

func (*UdpReplyTask) RunTask added in v1.4.1

func (u *UdpReplyTask) RunTask() int

运行

type UdpService

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

IServer 接口实现,定义一个Server服务类

func (*UdpService) AddConnId added in v1.4.1

func (u *UdpService) AddConnId() uint64

累加并获取自增ID

func (*UdpService) CallLogHandle added in v1.2.0

func (u *UdpService) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})

错误消息处理

func (*UdpService) CallOnConnStart

func (u *UdpService) CallOnConnStart(conn netInterface.IConnection)

调用连接OnConnStart Hook函数

func (*UdpService) CallOnConnStop

func (u *UdpService) CallOnConnStop(conn netInterface.IConnection)

调用连接OnConnStop Hook函数

func (*UdpService) CallOnReceiveCompleted

func (u *UdpService) CallOnReceiveCompleted(conn netInterface.IConnection, data []byte)

数据上传完成回调

func (*UdpService) CallOnReplyCompleted added in v1.2.0

func (u *UdpService) CallOnReplyCompleted(conn netInterface.IConnection, data []byte, param interface{}, ok bool, err error)

下发后回调

func (*UdpService) GetAcceptQueueCount added in v1.4.1

func (u *UdpService) GetAcceptQueueCount() (count int64, totalCount, outTimeCount uint64)

获取连接接入队列剩余数

func (*UdpService) GetConn

func (u *UdpService) GetConn(connId uint64) (netInterface.IConnection, bool)

func (*UdpService) GetConnMgr

func (u *UdpService) GetConnMgr() netInterface.IConnManager

得到链接管理

func (*UdpService) GetRecInfo added in v1.4.1

func (u *UdpService) GetRecInfo() (count, byteSize uint64)

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

func (*UdpService) GetRepInfo added in v1.4.1

func (u *UdpService) GetRepInfo() (count, byteSize, errCount uint64)

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

func (*UdpService) GetStartTime added in v1.4.1

func (u *UdpService) GetStartTime() time.Time

获取连接启动时间

func (*UdpService) GetTotalQueueCount added in v1.2.0

func (u *UdpService) GetTotalQueueCount() (receiveCount int64, receiveTotalCount, receiveOutTimeCount uint64, replyCount int64, replyTotalCount, replyOutTimeCount uint64)

获取队列剩余数

func (*UdpService) SetCreateReceiver

func (u *UdpService) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)

设置创建分包策略方法

func (*UdpService) SetLogHandle added in v1.2.0

func (u *UdpService) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg ...interface{}))

func (*UdpService) SetOnConnStart

func (u *UdpService) SetOnConnStart(hookFunc func(netInterface.IConnection))

设置该Server的连接创建时Hook函数

func (*UdpService) SetOnConnStop

func (u *UdpService) SetOnConnStop(hookFunc func(netInterface.IConnection))

设置该Server的连接断开时的Hook函数

func (*UdpService) SetOnReceiveCompleted

func (u *UdpService) SetOnReceiveCompleted(hookFunc func(netInterface.IConnection, []byte))

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

func (*UdpService) SetOnReplyCompleted added in v1.2.0

func (u *UdpService) SetOnReplyCompleted(hookFunc func(netInterface.IConnection, []byte, interface{}, bool, error))

func (*UdpService) Start

func (u *UdpService) Start()

开启网络服务

func (*UdpService) Stop

func (u *UdpService) Stop()

停止服务

Jump to

Keyboard shortcuts

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