-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlistener.go
55 lines (42 loc) · 979 Bytes
/
listener.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
package gnet
import (
"net"
"sync/atomic"
)
var (
_listenerIdCounter uint32 = 0
)
// interface for Listener
type Listener interface {
GetListenerId() uint32
GetConnection(connectionId uint32) Connection
// 广播消息
// broadcast packet to accepted connections
Broadcast(packet Packet)
// Addr returns the listener's network address.
Addr() net.Addr
Close()
}
type ListenerConfig struct {
AcceptConfig ConnectionConfig
AcceptConnectionCreator AcceptConnectionCreator
ListenerHandler ListenerHandler
// ws或wss的http监听路径,如"/ws"或"/wss"
Path string
// 签名cert文件,wss专用
CertFile string
// 签名key文件,wss专用
KeyFile string
}
type baseListener struct {
// unique listener id
listenerId uint32
config *ListenerConfig
handler ListenerHandler
}
func (l *baseListener) GetListenerId() uint32 {
return l.listenerId
}
func newListenerId() uint32 {
return atomic.AddUint32(&_listenerIdCounter, 1)
}