-
Notifications
You must be signed in to change notification settings - Fork 72
/
grpcServer.go
executable file
·63 lines (51 loc) · 1.34 KB
/
grpcServer.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
package main
import (
"fmt"
"log"
"net"
"net/rpc"
"sync"
"bzza.com/controllers"
"bzza.com/models"
)
func grpcServer() {
newServer := rpc.NewServer()
newServer.Register(new(Arith))
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":8888")
if e != nil {
log.Fatal("listen error:", e)
}
fmt.Println("Grpc服务启动")
newServer.Accept(l)
}
type Arith int
var grpcMql5Lock = new(sync.Mutex)
func (t *Arith) Mql5(arrMql5 *[]*models.Mql5, reply *uint64) error {
grpcMql5Lock.Lock()
defer grpcMql5Lock.Unlock()
*reply = 0
for _, mql5Addr := range *arrMql5 {
v, ok := models.SyncMapMql5.Load((*mql5Addr).Symbol)
if ok && (*mql5Addr).UnixNano <= v.(*models.Mql5).UnixNano {
continue
}
*reply += 1 //有效更新数
controllers.BroadcastSame(&models.WsConn, &((*mql5Addr).Symbol), mql5Addr) //新数据到达 推送
models.SyncMapMql5.Store((*mql5Addr).Symbol, mql5Addr)
}
return nil
}
func (t *Arith) CollectMeteringData(cleanOk bool, reply *map[string]uint64) error { //收集统计用户流量
models.SumNetworkInLock.Lock()
defer models.SumNetworkInLock.Unlock()
models.SyncMapSumNetworkIn.Range(func(k, v interface{}) bool {
kStr, ok := k.(string)
if ok {
(*reply)[kStr] = v.(uint64)
models.SyncMapSumNetworkIn.Delete(k)
}
return true
})
return nil
}