-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsessionwrapper.go
66 lines (58 loc) · 1.99 KB
/
sessionwrapper.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
64
65
66
// Copyright (c) 2014 SameGoal LLC. All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wc
import (
"sync"
"time"
)
// Special cases to think about:
// * duplicate back channel
// * noop message on back channel
// * buffered proxy mode (ensure flushing all messages)
// * 'Unknown SID' error message with HTTP status 400
// * other ChannelRequest.Error error values (special cases?)
// * XSS escaping messages for client
// * backchannel handoff
// * messages delivered when no back channel exists for a session
// * client side session reconnects after server crash
// * chunk compression
// Tasks for application level:
// * sharding comet server? (moving sessions across servers?)
// * restart server without dropping back channels
// * expvar stats: # sessions, # backchannels, # pending messages, etc
var (
mutex sync.Mutex
sessionWrapperMap map[string]*sessionWrapper
)
func init() {
sessionWrapperMap = make(map[string]*sessionWrapper)
}
type sessionWrapper struct {
Session
si *SessionInfo
reqNotifier chan *reqRegister
noopTimer, longBackChannelTimer *time.Timer
bc *reqRegister
backChannelCloseNotifier <-chan bool
p *padder
// backChannelBytes is the number of non-ACKed bytes on the back channel
// (based upon the last AID received on a back or forward channel)
backChannelBytes int
}
func newSessionWrapper(session Session) *sessionWrapper {
sw := &sessionWrapper{
Session: session,
si: &SessionInfo{-1, -1},
reqNotifier: make(chan *reqRegister),
noopTimer: time.NewTimer(30 * time.Second),
longBackChannelTimer: time.NewTimer(4 * 60 * time.Second),
bc: nil,
backChannelCloseNotifier: nil,
p: nil,
backChannelBytes: 0,
}
sw.noopTimer.Stop()
sw.longBackChannelTimer.Stop()
return sw
}