forked from googollee/go-engine.io
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsessions.go
More file actions
47 lines (37 loc) · 720 Bytes
/
sessions.go
File metadata and controls
47 lines (37 loc) · 720 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
41
42
43
44
45
46
47
package engineio
import (
"sync"
)
type Sessions interface {
Get(id string) Conn
Set(id string, conn Conn)
Remove(id string)
}
type serverSessions struct {
sessions map[string]Conn
locker sync.RWMutex
}
func newServerSessions() *serverSessions {
return &serverSessions{
sessions: make(map[string]Conn),
}
}
func (s *serverSessions) Get(id string) Conn {
s.locker.RLock()
defer s.locker.RUnlock()
ret, ok := s.sessions[id]
if !ok {
return nil
}
return ret
}
func (s *serverSessions) Set(id string, conn Conn) {
s.locker.Lock()
defer s.locker.Unlock()
s.sessions[id] = conn
}
func (s *serverSessions) Remove(id string) {
s.locker.Lock()
defer s.locker.Unlock()
delete(s.sessions, id)
}