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 ¶
- Variables
- func InitClientChannel(conf *config.Config)
- type ChannelBucket
- type ChannelBucketList
- func (c *ChannelBucketList) Close()
- func (c *ChannelBucketList) CountAll() (count int64)
- func (c *ChannelBucketList) CountApp(appId int) (count int64)
- func (c *ChannelBucketList) Get(appId int, uuid string, newFlag bool) (IChannel, error)
- func (c *ChannelBucketList) GetAll() ([]IChannel, error)
- func (c *ChannelBucketList) GetApp(appId int) ([]IChannel, error)
- func (c *ChannelBucketList) New(appId int, uuid string) (IChannel, *ChannelBucket, error)
- func (c *ChannelBucketList) Remove(appId int, uuid string) error
- type ConnChannel
- func (u *ConnChannel) AddConn(appId int, uuid string, conn *Connection) (*list.Element, error)
- func (u *ConnChannel) AddToken(string, string) error
- func (u *ConnChannel) CheckToken(string, string) error
- func (u *ConnChannel) Close() error
- func (u *ConnChannel) DelConn(appId int, uuid string, e *list.Element)
- func (u *ConnChannel) PushMsg(appId int, uuid string, msg []byte) error
- type Connection
- type IChannel
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 ¶
Types ¶
type ChannelBucket ¶
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) 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) 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
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退出时主动调用)
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 客户端连接抽象层
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
Click to show internal directories.
Click to hide internal directories.