...
1
2
3
4
5 package http2
6
7 import "math"
8
9
10
11
12
13 func NewRandomWriteScheduler() WriteScheduler {
14 return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)}
15 }
16
17 type randomWriteScheduler struct {
18
19 zero writeQueue
20
21
22
23
24 sq map[uint32]*writeQueue
25
26
27 queuePool writeQueuePool
28 }
29
30 func (ws *randomWriteScheduler) OpenStream(streamID uint32, options OpenStreamOptions) {
31
32 }
33
34 func (ws *randomWriteScheduler) CloseStream(streamID uint32) {
35 q, ok := ws.sq[streamID]
36 if !ok {
37 return
38 }
39 delete(ws.sq, streamID)
40 ws.queuePool.put(q)
41 }
42
43 func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityParam) {
44
45 }
46
47 func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) {
48 if wr.isControl() {
49 ws.zero.push(wr)
50 return
51 }
52 id := wr.StreamID()
53 q, ok := ws.sq[id]
54 if !ok {
55 q = ws.queuePool.get()
56 ws.sq[id] = q
57 }
58 q.push(wr)
59 }
60
61 func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) {
62
63 if !ws.zero.empty() {
64 return ws.zero.shift(), true
65 }
66
67 for streamID, q := range ws.sq {
68 if wr, ok := q.consume(math.MaxInt32); ok {
69 if q.empty() {
70 delete(ws.sq, streamID)
71 ws.queuePool.put(q)
72 }
73 return wr, true
74 }
75 }
76 return FrameWriteRequest{}, false
77 }
78
View as plain text