forked from diamondcdn/fasthttp-http2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streams.go
48 lines (42 loc) · 819 Bytes
/
streams.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
package http2
type Streams []*Stream
func (strms *Streams) Search(id uint32) *Stream {
for _, strm := range *strms {
if strm.ID() == id {
return strm
}
}
return nil
}
func (strms *Streams) Del(id uint32) {
if len(*strms) == 1 && (*strms)[0].ID() == id {
*strms = (*strms)[:0]
return
}
for i, strm := range *strms {
if strm.ID() == id {
*strms = append((*strms)[:i], (*strms)[i+1:]...)
return
}
}
}
func (strms Streams) GetFirstOf(frameType FrameType) *Stream {
for _, strm := range strms {
if strm.origType == frameType {
return strm
}
}
return nil
}
func (strms Streams) getPrevious(frameType FrameType) *Stream {
cnt := 0
for i := len(strms) - 1; i >= 0; i-- {
if strms[i].origType == frameType {
if cnt != 0 {
return strms[i]
}
cnt++
}
}
return nil
}