connect

package
v0.0.0-...-02b4230 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

*

*
* @author liangjf
* @create on 2020/5/20
* @version 1.0

*

*
* @author liangjf
* @create on 2020/5/20
* @version 1.0

*

*
* @author liangjf
* @create on 2020/5/21
* @version 1.0

*

*
* @author liangjf
* @create on 2020/5/21
* @version 1.0

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChannelBucketChannelNotExist = errors.New("channel not exist")
	ErrAppNotExist                  = errors.New("app not exist")
)
View Source
var (
	ErrMaxSubscriberPerChannel = errors.New("error max subscriber per channel")
	ErrTypeConn                = errors.New("failed type Connection")
	ErrNoThisSubConn           = errors.New("no this sub Connection")
)
View Source
var (
	MaxSubscriberPerChannel = 10000
)

Functions

func InitClientChannel

func InitClientChannel(conf *config.Config)

Types

type ChannelBucket

type ChannelBucket struct {
	Data map[string]IChannel
	// contains filtered or unexported fields
}

ChannelBucket a bucket

func (*ChannelBucket) Lock

func (c *ChannelBucket) Lock()

func (*ChannelBucket) RLock

func (c *ChannelBucket) RLock()

func (*ChannelBucket) RUnlock

func (c *ChannelBucket) RUnlock()

func (*ChannelBucket) UnLock

func (c *ChannelBucket) UnLock()

type ChannelBucketList

type ChannelBucketList struct {
	Buckets map[int][]*ChannelBucket //每个app分桶, 提高查询效率
	// contains filtered or unexported fields
}

ChannelBucketList channel桶

func GetClientChannel

func GetClientChannel() *ChannelBucketList

func NewBucketList

func NewBucketList(conf *config.Config) *ChannelBucketList

NewBucketList 创建channel桶

func (*ChannelBucketList) Close

func (c *ChannelBucketList) Close()

Close 关闭本地缓存

func (*ChannelBucketList) CountAll

func (c *ChannelBucketList) CountAll() (count int64)

CountAll 计算gateway的客户端总数

func (*ChannelBucketList) CountApp

func (c *ChannelBucketList) CountApp(appId int) (count int64)

CountApp 计算gateway的某app客户端总数

func (*ChannelBucketList) Get

func (c *ChannelBucketList) Get(appId int, uuid string, newFlag bool) (IChannel, error)

Get 获取客户端通道

func (*ChannelBucketList) GetAll

func (c *ChannelBucketList) GetAll() ([]IChannel, error)

GetApp 获取某app客户端通道

func (*ChannelBucketList) GetApp

func (c *ChannelBucketList) GetApp(appId int) ([]IChannel, error)

GetApp 获取某app客户端通道

func (*ChannelBucketList) New

func (c *ChannelBucketList) New(appId int, uuid string) (IChannel, *ChannelBucket, error)

New 创建新的客户端channel

func (*ChannelBucketList) Remove

func (c *ChannelBucketList) Remove(appId int, uuid string) error

Remove 删除channel本地缓存

type ConnChannel

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

ConnChannel 每个client的读写channel

func (*ConnChannel) AddConn

func (u *ConnChannel) AddConn(appId int, uuid string, conn *Connection) (*list.Element, error)

创建一个客户端连接

func (*ConnChannel) AddToken

func (u *ConnChannel) AddToken(string, string) error

AddToken 客户端连接添加token权限

func (*ConnChannel) CheckToken

func (u *ConnChannel) CheckToken(string, string) error

CheckToken 校验客户端连接token是否超时

func (*ConnChannel) Close

func (u *ConnChannel) Close() error

Close 关闭所有客户端连接, 删除所有客户端抽象(server退出时主动调用)

func (*ConnChannel) DelConn

func (u *ConnChannel) DelConn(appId int, uuid string, e *list.Element)

DelConn 删除客户端连接抽象(客户端close时调用)

func (*ConnChannel) PushMsg

func (u *ConnChannel) PushMsg(appId int, uuid string, msg []byte) error

PushMsg 写推送消息到通道

type Connection

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

Connection 客户端连接抽象层

func NewConnect

func NewConnect(conn net.Conn, proto string) *Connection

NewConnect 创建客户端连接抽象

func (*Connection) HandleWriteMsg2Connect

func (c *Connection) HandleWriteMsg2Connect(appId int, uuid string)

HandleWriteMsg2Connect 客户端推送消息通道监听和写客户端

func (*Connection) WriteMsg2Connect

func (c *Connection) WriteMsg2Connect(appId int, uuid string, msg []byte)

WriteMsg2Connect 对外暴露, 用于推送消息到chan的转换

type IChannel

type IChannel interface {
	//AddToken 客户端连接添加token权限
	AddToken(string, string) error
	//CheckToken 校验客户端连接token权限
	CheckToken(string, string) error
	//PushMsg 推送消息
	PushMsg(int, string, []byte) error
	//创建一个客户端连接
	AddConn(int, string, *Connection) (*list.Element, error)
	//删除一个客户端连接
	DelConn(int, string, *list.Element)
	//Close 关闭客户channel
	Close() error
}

IChannel 客户端分配channel通信 不直接用conn维护客户端连接, 而是用channel, 是为了和通信协议解耦, 支持任意通信协议(tcp, ws, udp...)

func NewConnChannel

func NewConnChannel() IChannel

Jump to

Keyboard shortcuts

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