1
// Copyright 2014 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
9
// NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2
10
// priorities. Control frames like SETTINGS and PING are written before DATA
11
// frames, but if no control frames are queued and multiple streams have queued
12
// HEADERS or DATA frames, Pop selects a ready stream arbitrarily.
13
func NewRandomWriteScheduler() WriteScheduler {
14
return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)}
17
type randomWriteScheduler struct {
18
// zero are frames not associated with a specific stream.
21
// sq contains the stream-specific queues, keyed by stream ID.
22
// When a stream is idle, closed, or emptied, it's deleted
24
sq map[uint32]*writeQueue
26
// pool of empty queues for reuse.
27
queuePool writeQueuePool
30
func (ws *randomWriteScheduler) OpenStream(streamID uint32, options OpenStreamOptions) {
31
// no-op: idle streams are not tracked
34
func (ws *randomWriteScheduler) CloseStream(streamID uint32) {
35
q, ok := ws.sq[streamID]
39
delete(ws.sq, streamID)
43
func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityParam) {
44
// no-op: priorities are ignored
47
func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) {
55
q = ws.queuePool.get()
61
func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) {
62
// Control and RST_STREAM frames first.
64
return ws.zero.shift(), true
66
// Iterate over all non-idle streams until finding one that can be consumed.
67
for streamID, q := range ws.sq {
68
if wr, ok := q.consume(math.MaxInt32); ok {
70
delete(ws.sq, streamID)
76
return FrameWriteRequest{}, false