-
Notifications
You must be signed in to change notification settings - Fork 85
/
stat.go
47 lines (38 loc) · 859 Bytes
/
stat.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
// Proxy statistics.
package main
import (
"sync"
"sync/atomic"
)
var status struct {
cliCnt int32 // number of client connections
srvConnCnt map[string]int // number of connections for each host:port
srvConnCntMutex sync.Mutex
}
func initStat() {
if !debug {
return
}
status.srvConnCnt = make(map[string]int)
}
func incCliCnt() int32 {
atomic.AddInt32(&status.cliCnt, 1)
return status.cliCnt
}
func decCliCnt() int32 {
atomic.AddInt32(&status.cliCnt, -1)
return status.cliCnt
}
func addSrvConnCnt(srv string, delta int) int {
status.srvConnCntMutex.Lock()
status.srvConnCnt[srv] += delta
cnt := status.srvConnCnt[srv]
status.srvConnCntMutex.Unlock()
return int(cnt)
}
func incSrvConnCnt(srv string) int {
return addSrvConnCnt(srv, 1)
}
func decSrvConnCnt(srv string) int {
return addSrvConnCnt(srv, -1)
}