-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsession.go
60 lines (52 loc) · 1.19 KB
/
session.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
package gott
type session struct {
client *Client
clean bool
ID string
MessageStore *messageStore
}
func newSession(client *Client, cleanFlag bool) *session {
return &session{
client: client,
clean: cleanFlag,
MessageStore: newMessageStore(),
ID: client.ClientID,
}
}
func (s *session) load() error {
//start := time.Now()
err := GOTT.SessionStore.get(s.ID, s)
//end := time.Since(start)
//LogBench("session load took:", end)
return err
}
func (s *session) put() error {
//start := time.Now()
err := GOTT.SessionStore.set(s.ID, s)
//end := time.Since(start)
//LogBench("session put took:", end)
return err
}
func (s *session) storeMessage(packetID uint16, msg *clientMessage) {
s.MessageStore.store(packetID, msg)
if !s.clean {
_ = s.put()
}
}
func (s *session) acknowledge(packetID uint16, status int32, delete bool) {
s.MessageStore.acknowledge(packetID, status, delete)
if !s.clean {
_ = s.put()
}
}
func (s *session) replay() {
if s.clean {
return
}
if s.client != nil {
s.MessageStore.RangeSorted(func(packetId uint16, cm *clientMessage) bool {
GOTT.PublishToClient(s.client, packetId, cm)
return true
})
}
}