5 Star 20 Fork 10

NightTC/Gobige

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ISessCallBack.go 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
package sess
import (
"gitee.com/night-tc/gobige/global"
"gitee.com/night-tc/gobige/logger"
"gitee.com/night-tc/gobige/msgdef"
"gitee.com/night-tc/gobige/msgdef/protomsg"
)
type ISessCallBack interface {
//连接被关闭的时候(这个回调会在任意协程上,所以需要注意安全)
SessClosed(sess INetSess)
//会话的验证回调 如果是连接客户端的上层需要重载实现验证逻辑,失败就返回错误,底层会关闭连接
SessVerify(msg msgdef.ISessionVerifyReqMsg, sess INetSess) error
//连接类型
GetProtocal() ProtocalEnum
}
// 连接被关闭的时候
func (this *NetSrv) SessClosed(sess INetSess) {
this.sessesByID.CompareAndDelete(sess.GetID(), sess)
}
/*
会话的验证回调
如果是连接客户端的上层需要重载实现验证逻辑,失败就返回错误,底层会关闭连接
*/
func (this *NetSrv) SessVerify(msg msgdef.ISessionVerifyReqMsg, sess INetSess) error {
sess.Send(&protomsg.ClientVerifySucceedRet{})
sess.SetVerify()
sess.SetID(msg.GetSessUID())
if !this.isClient {
sess.SetType(msg.GetSessType())
} else {
sess.SetType(global.ServerTypeClient)
}
this.PutSess(sess)
logger.Infof("SessVerify type:%d;key:%d;sess[%s]", msg.GetSessType(), msg.GetSessUID(), sess.RemoteAddr())
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/night-tc/gobige.git
git@gitee.com:night-tc/gobige.git
night-tc
gobige
Gobige
3e11984fb1ba

搜索帮助