-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadpool.go
More file actions
40 lines (37 loc) · 714 Bytes
/
loadpool.go
File metadata and controls
40 lines (37 loc) · 714 Bytes
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
package main
import (
"fmt"
"sync"
)
type ConnectPool struct {
mu sync.Mutex
m map[string]*connection
}
type connection struct {
SessionKey []byte
Akey []byte
}
func (cp *ConnectPool) Get(socket string) (*connection, error) {
cp.mu.Lock()
defer cp.mu.Unlock()
connBytes, ok := cp.m[socket]
if !ok {
return nil, fmt.Errorf("not found")
}
return connBytes, nil
}
func (cp *ConnectPool) Set(socket string, conn *connection) {
cp.mu.Lock()
defer cp.mu.Unlock()
cp.m[socket] = conn
}
func (cp *ConnectPool) Delete(socket string) {
cp.mu.Lock()
defer cp.mu.Unlock()
delete(cp.m, socket)
}
func CtearConnectPool() *ConnectPool {
return &ConnectPool{
m: make(map[string]*connection),
}
}