-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconn_manger.go
64 lines (52 loc) · 1013 Bytes
/
conn_manger.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
62
63
64
/**
* @Author: llh
* @Date: 2019-06-01 15:08:12
* @Last Modified by: llh
*/
package tfg
import (
"sync"
"sync/atomic"
)
type ConnManger interface {
Len() int64
CloseAllConn()
}
type connManager struct {
conns *sync.Map
connCount int64
connCache *sync.Pool
inCache *sync.Pool
handleReqCache *sync.Pool
}
func (m *connManager) getIn() {
}
func (m *connManager) incConnCount() {
atomic.AddInt64(&m.connCount, 1)
}
func (m *connManager) decConnCount() {
atomic.AddInt64(&m.connCount, -1)
}
func (m *connManager) delete(fd int) {
m.conns.Delete(fd)
}
func (m *connManager) get(fd int) (*conn, bool) {
v, ok := m.conns.Load(fd)
if !ok {
return nil, ok
}
return v.(*conn), true
}
func (m *connManager) add(key int, v Conn) {
m.conns.Store(key, v)
}
func (m *connManager) Len() int64 {
return m.connCount
}
func (m *connManager) CloseAllConn() {
m.conns.Range(func(key, value interface{}) bool {
conn := value.(Conn)
conn.Close()
return true
})
}