-
Notifications
You must be signed in to change notification settings - Fork 882
/
sysmsg.go
61 lines (47 loc) · 1.55 KB
/
sysmsg.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
51
52
53
54
55
56
57
58
59
60
61
package cellnet
import "fmt"
type SessionInit struct {
}
type SessionAccepted struct {
}
type SessionConnected struct {
}
type SessionConnectError struct {
}
type CloseReason int32
const (
CloseReason_IO CloseReason = iota // 普通IO断开
CloseReason_Manual // 关闭前,调用过Session.Close
)
func (self CloseReason) String() string {
switch self {
case CloseReason_IO:
return "IO"
case CloseReason_Manual:
return "Manual"
}
return "Unknown"
}
type SessionClosed struct {
Reason CloseReason // 断开原因
}
// udp通知关闭,内部使用
type SessionCloseNotify struct {
}
func (self *SessionInit) String() string { return fmt.Sprintf("%+v", *self) }
func (self *SessionAccepted) String() string { return fmt.Sprintf("%+v", *self) }
func (self *SessionConnected) String() string { return fmt.Sprintf("%+v", *self) }
func (self *SessionConnectError) String() string { return fmt.Sprintf("%+v", *self) }
func (self *SessionClosed) String() string { return fmt.Sprintf("%+v", *self) }
func (self *SessionCloseNotify) String() string { return fmt.Sprintf("%+v", *self) }
// 标记系统消息
func (self *SessionInit) SystemMessage() {}
func (self *SessionAccepted) SystemMessage() {}
func (self *SessionConnected) SystemMessage() {}
func (self *SessionConnectError) SystemMessage() {}
func (self *SessionClosed) SystemMessage() {}
func (self *SessionCloseNotify) SystemMessage() {}
// 使用类型断言判断是否为系统消息
type SystemMessageIdentifier interface {
SystemMessage()
}