session

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int
const (
	Conn Kind = iota + 1 // 连接SESSION
	User                 // 用户SESSION
)

func (Kind) String

func (k Kind) String() string

String 获取会话类型名称 @return @1 string 会话类型名称

type Session

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

func NewSession

func NewSession() *Session

NewSession 创建一个会话实例 @return @1 *Session 会话实例

func (*Session) AddConn

func (s *Session) AddConn(conn network.Conn)

AddConn 添加连接 @param conn network.Conn 连接对象

func (*Session) Bind

func (s *Session) Bind(cid, uid int64) error

Bind 绑定用户ID @param cid int64 连接ID @param uid int64 用户ID @return @1 error 错误信息

func (*Session) Broadcast

func (s *Session) Broadcast(kind Kind, disconnect bool, buf buffer.Buffer) (int64, error)

Broadcast 推送广播消息(异步) @param kind Kind 会话类型 @param disconnect bool 推送后是否断开连接 @param buf buffer.Buffer 消息内容 @return @1 int64 成功推送的数量 @return @2 error 错误信息

func (*Session) Close

func (s *Session) Close(kind Kind, target int64, force ...bool) error

Close 关闭会话 @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @param force ...bool 是否强制关闭 @return @1 error 错误信息

func (*Session) Has

func (s *Session) Has(kind Kind, target int64) (ok bool, err error)

Has 判断会话是否存在 @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @return @1 bool 是否存在 @return @2 error 错误信息

func (*Session) LocalAddr

func (s *Session) LocalAddr(kind Kind, target int64) (net.Addr, error)

LocalAddr 获取本地地址 @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @return @1 net.Addr 本地地址 @return @2 error 错误信息

func (*Session) LocalIP

func (s *Session) LocalIP(kind Kind, target int64) (string, error)

LocalIP 获取本地IP @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @return @1 string 本地IP地址 @return @2 error 错误信息

func (*Session) Multicast

func (s *Session) Multicast(kind Kind, targets []int64, disconnect bool, buf buffer.Buffer) (int64, error)

Multicast 推送组播消息(异步) @param kind Kind 会话类型 @param targets []int64 会话目标列表(连接ID或用户ID) @param disconnect bool 推送后是否断开连接 @param buf buffer.Buffer 消息内容 @return @1 int64 成功推送的数量 @return @2 error 错误信息

func (*Session) Publish added in v2.3.0

func (s *Session) Publish(channel string, disconnect bool, buf buffer.Buffer) (int64, error)

Publish 发布频道消息(异步) @param channel string 频道名称 @param disconnect bool 推送后是否断开连接 @param buf buffer.Buffer 消息内容 @return @1 int64 成功推送的数量 @return @2 error 错误信息

func (*Session) Push

func (s *Session) Push(kind Kind, target int64, disconnect bool, buf buffer.Buffer) error

Push 推送消息(异步) @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @param disconnect bool 推送后是否断开连接 @param buf buffer.Buffer 消息内容 @return @1 error 错误信息

func (*Session) RemConn

func (s *Session) RemConn(conn network.Conn) bool

RemConn 移除连接 在同一把写锁内完成存在性检查与移除,调用方无需先Has再RemConn两次查找; 并发重复移除时仅首个调用返回true,可防止重复移除导致的计数失衡 @param conn network.Conn 连接对象 @return @1 bool 连接是否已登记并被移除

func (*Session) RemoteAddr

func (s *Session) RemoteAddr(kind Kind, target int64) (net.Addr, error)

RemoteAddr 获取远端地址 @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @return @1 net.Addr 远端地址 @return @2 error 错误信息

func (*Session) RemoteIP

func (s *Session) RemoteIP(kind Kind, target int64) (string, error)

RemoteIP 获取远端IP @param kind Kind 会话类型 @param target int64 会话目标(连接ID或用户ID) @return @1 string 远端IP地址 @return @2 error 错误信息

func (*Session) Stat

func (s *Session) Stat(kind Kind) (int64, error)

Stat 统计会话总数 @param kind Kind 会话类型 @return @1 int64 会话数量 @return @2 error 错误信息

func (*Session) Subscribe added in v2.3.0

func (s *Session) Subscribe(kind Kind, targets []int64, channel string) (err error)

Subscribe 订阅频道 @param kind Kind 会话类型 @param targets []int64 会话目标列表(连接ID或用户ID) @param channel string 频道名称 @return @1 error 错误信息

func (*Session) Unbind

func (s *Session) Unbind(uid int64) (int64, error)

Unbind 解绑用户ID @param uid int64 用户ID @return @1 int64 连接ID @return @2 error 错误信息

func (*Session) Unsubscribe added in v2.3.0

func (s *Session) Unsubscribe(kind Kind, targets []int64, channel string) (err error)

Unsubscribe 取消订阅频道 @param kind Kind 会话类型 @param targets []int64 会话目标列表(连接ID或用户ID) @param channel string 频道名称 @return @1 error 错误信息

Jump to

Keyboard shortcuts

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