forked from dgrr/http2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.go
More file actions
127 lines (103 loc) · 2.45 KB
/
Copy pathstream.go
File metadata and controls
127 lines (103 loc) · 2.45 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package http2
import (
"sync"
"time"
"github.com/valyala/fasthttp"
)
type StreamState int8
const (
StreamStateIdle StreamState = iota
StreamStateReserved
StreamStateOpen
StreamStateHalfClosed
StreamStateClosed
)
func (ss StreamState) String() string {
switch ss {
case StreamStateIdle:
return "Idle"
case StreamStateReserved:
return "Reserved"
case StreamStateOpen:
return "Open"
case StreamStateHalfClosed:
return "HalfClosed"
case StreamStateClosed:
return "Closed"
}
return "IDK"
}
type Stream struct {
id uint32
window int64
state StreamState
ctx *fasthttp.RequestCtx
scheme []byte
previousHeaderBytes []byte
// keeps track of the number of header blocks received
headerBlockNum int
// original type
origType FrameType
startedAt time.Time
headersFinished bool
// processing is true while the request handler runs in its own
// goroutine. Owned by the handleStreams loop.
processing bool
// sendQuota tracks send flow-control credit relative to the client's
// SETTINGS_INITIAL_WINDOW_SIZE: WINDOW_UPDATEs add, DATA sends subtract.
// Available window = initialStreamWin + sendQuota. Guarded by
// serverConn.fcMu.
sendQuota int64
// cancelled tells the handler goroutine to stop writing (stream was
// reset or the connection is closing). Guarded by serverConn.fcMu.
cancelled bool
}
var streamPool = sync.Pool{
New: func() interface{} {
return &Stream{}
},
}
func NewStream(id uint32, win int32) *Stream {
strm := streamPool.Get().(*Stream)
strm.id = id
strm.window = int64(win)
strm.state = StreamStateIdle
strm.headersFinished = false
strm.startedAt = time.Time{}
strm.previousHeaderBytes = strm.previousHeaderBytes[:0]
strm.ctx = nil
strm.scheme = []byte("https")
strm.origType = 0
strm.headerBlockNum = 0
strm.processing = false
strm.sendQuota = 0
strm.cancelled = false
return strm
}
func (s *Stream) ID() uint32 {
return s.id
}
func (s *Stream) SetID(id uint32) {
s.id = id
}
func (s *Stream) State() StreamState {
return s.state
}
func (s *Stream) SetState(state StreamState) {
s.state = state
}
func (s *Stream) Window() int32 {
return int32(s.window)
}
func (s *Stream) SetWindow(win int32) {
s.window = int64(win)
}
func (s *Stream) IncrWindow(win int32) {
s.window += int64(win)
}
func (s *Stream) Ctx() *fasthttp.RequestCtx {
return s.ctx
}
func (s *Stream) SetData(ctx *fasthttp.RequestCtx) {
s.ctx = ctx
}