connection

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const QueueServedLength = 10000

下线ID小于10000个则不使用

Variables

View Source
var ConnectionClearSignal = make(chan bool, 100)

清除通道记录信号

View Source
var ConnectionCollection = ConnectionMap{}

通道记录集合

View Source
var ConnectionNextAvailable = struct {
	availableTimeStart          bool
	connectionNextAvailableTime int64
	connectionNextReuseTime     int64
	queueLen                    int
}{
	// contains filtered or unexported fields
}

管道锁检测

Functions

func InitConnection

func InitConnection()

初始化前缀

Types

type Connection

type Connection struct {
	ConnectionId string //链接信息唯一ID

	Timer   *time.Timer //心跳检测超时器
	IsBreak bool        //是否活跃
	// contains filtered or unexported fields
}

链接信息

func GetConnectionLink(connectionId string) (conn *Connection, err error)

获取管道记录

func OnlineConnection

func OnlineConnection(wsConn *websocket.Conn) (conn *Connection, err error)

初始化连接信息

func (*Connection) Close

func (conn *Connection) Close()

Connection-关闭链接

func (*Connection) ReadMessage

func (conn *Connection) ReadMessage() (data []byte, err error)

Connection-读取链接内容

func (*Connection) WriteMessage

func (conn *Connection) WriteMessage(data []byte) (err error)

Connection-写入链接内容

type ConnectionCounts

type ConnectionCounts struct {
	MaxConnectionNum int64 //当前自增的通道记录

	ConnectionLinkNum      int //当前连接中的通道数量
	ConnectionWaitClearNum int //当前待清理的删除通道数量
	// contains filtered or unexported fields
}

通道计数

type ConnectionInfo

type ConnectionInfo struct {
	Ip           string `json:"ip"`            //网关连接ip
	HttpPort     string `json:"http_port"`     //http端口
	Pid          string `json:"pid"`           //进程id
	Cid          string `json:"cid"`           //自增id
	Range        string `json:"range"`         //随机1-65535
	ConnectionId string `json:"connection_id"` //加密后的管道id
}

func DecodeConnection

func DecodeConnection(connectionId string) (connectionInfo ConnectionInfo, err error)

解密管道信息

type ConnectionMap

type ConnectionMap struct {
	ConnectionList map[string]*Connection //所有的socket通道信息记录

	TmpConnectionList map[string]*Connection //当IsClearIng为true的时候 会把链接进来的用户存到当前MAP中一份 用来异步清理MAP

	DeletedWaitReuse *ConnectionQueue //已删除可以复用的通道数

	Prefix string //前缀

	ConnectionCounts *ConnectionCounts //计数器

	IsClearIng bool //是否正在清理

	Mutex sync.Mutex //锁防止生成重复的通道key值
}

链接MAP结构体

type ConnectionQueue

type ConnectionQueue struct {
	Header *ConnectionQueueItem //第一个元素 减少复杂度
	Tail   *ConnectionQueueItem //最后一个元素 减少复杂度
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue() *ConnectionQueue

创建队

func (*ConnectionQueue) DeQueue

func (s *ConnectionQueue) DeQueue() (responseItem *ConnectionQueueBody, err error)

出队-尾取

func (*ConnectionQueue) EnQueue

func (s *ConnectionQueue) EnQueue(body *ConnectionQueueBody) bool

入队-头插

func (*ConnectionQueue) GetLen

func (s *ConnectionQueue) GetLen() int

获取队的长度

type ConnectionQueueBody

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

type ConnectionQueueItem

type ConnectionQueueItem struct {
	ConnectionQueueBody *ConnectionQueueBody //管道的内容

	Prev *ConnectionQueueItem //链表上一个元素
	Next *ConnectionQueueItem //链表下一个元素
}

Jump to

Keyboard shortcuts

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