73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package gateway
|
|
|
|
import (
|
|
"go_dreamfactory/pb"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
)
|
|
|
|
type (
|
|
// IAgent 用户代理对象接口定义
|
|
IAgent interface {
|
|
SessionId() string
|
|
IP() string
|
|
Group() int32
|
|
UserId() string
|
|
WorkerId() string
|
|
Bind(uId string, wId string)
|
|
SetCrosssId(wId string)
|
|
CrosssWorkerId() string
|
|
UnBind()
|
|
WriteMsg(msg *pb.UserMessage) (err error)
|
|
WriteBytes(data []byte) (err error)
|
|
HandleMessage(msg *pb.UserMessage) (err error)
|
|
PushQueueChange()
|
|
Close() //主动关闭接口
|
|
}
|
|
// IGateway 网关模块 接口定义
|
|
IGateway interface {
|
|
core.IModule
|
|
log.ILogger
|
|
Service() base.IRPCXService
|
|
Connect(a IAgent)
|
|
DisConnect(a IAgent)
|
|
LoginNotice(a IAgent)
|
|
GetMsgDistribute(msgmid, msguid string) (rule string, ok bool)
|
|
InLoginQueue(sessionId string, login *pb.UserMessage) (index int32, err error)
|
|
IsOpenLoginQueue() bool
|
|
}
|
|
)
|
|
|
|
var msgPool = &sync.Pool{
|
|
New: func() interface{} {
|
|
return &pb.AgentMessage{}
|
|
},
|
|
}
|
|
|
|
func getmsg() *pb.AgentMessage {
|
|
req := msgPool.Get().(*pb.AgentMessage)
|
|
return req
|
|
}
|
|
|
|
func putmsg(r *pb.AgentMessage) {
|
|
msgPool.Put(r)
|
|
}
|
|
|
|
var msgreplyPool = &sync.Pool{
|
|
New: func() interface{} {
|
|
return &pb.RPCMessageReply{}
|
|
},
|
|
}
|
|
|
|
func getmsgreply() *pb.RPCMessageReply {
|
|
reply := msgreplyPool.Get().(*pb.RPCMessageReply)
|
|
return reply
|
|
}
|
|
|
|
func putmsgreply(r *pb.RPCMessageReply) {
|
|
msgreplyPool.Put(r)
|
|
}
|