/
mapping.go
50 lines (43 loc) · 941 Bytes
/
mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package router
import (
"context"
"git.golaxy.org/core/ec"
"git.golaxy.org/framework/plugins/gate"
)
// IMapping 映射
type IMapping interface {
context.Context
// GetEntity 获取实体
GetEntity() ec.ConcurrentEntity
// GetSession 获取会话
GetSession() gate.ISession
// GetCliAddr 获取客户端地址
GetCliAddr() string
}
type _Mapping struct {
context.Context
terminate context.CancelFunc
entity ec.ConcurrentEntity
session gate.ISession
cliAddr string
}
// GetEntity 获取实体
func (m *_Mapping) GetEntity() ec.ConcurrentEntity {
return m.entity
}
// GetSession 获取会话
func (m *_Mapping) GetSession() gate.ISession {
return m.session
}
// GetCliAddr 获取客户端地址
func (m *_Mapping) GetCliAddr() string {
return m.cliAddr
}
func (m *_Mapping) mainLoop(router *_Router) {
select {
case <-m.Done():
return
case <-m.session.Done():
router.CleanSession(m.session.GetId())
}
}