forked from davyxu/cellnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer.go
56 lines (39 loc) · 1006 Bytes
/
peer.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
package cellnet
// 端, 可通过接口查询获得更多接口支持,如PeerProperty,ContextSet, SessionAccessor
type Peer interface {
// 开启端,传入地址
Start() Peer
// 停止通讯端
Stop()
// Peer的类型(protocol.type),例如tcp.Connector/udp.Acceptor
TypeName() string
}
// Peer基础属性
type PeerProperty interface {
Name() string
Address() string
Queue() EventQueue
// 设置名称(可选)
SetName(v string)
// 设置Peer地址
SetAddress(v string)
// 设置Peer挂接队列(可选)
SetQueue(v EventQueue)
}
// 设置和获取自定义属性
type ContextSet interface {
SetContext(key interface{}, v interface{})
GetContext(key interface{}) (interface{}, bool)
FetchContext(key, valuePtr interface{}) bool
}
// 会话访问
type SessionAccessor interface {
// 获取一个连接
GetSession(int64) Session
// 遍历连接
VisitSession(func(Session) bool)
// 连接数量
SessionCount() int
// 关闭所有连接
CloseAllSession()
}