// Copyright 2014 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.//go:build !(go1.27 && !http2legacy)package http2import// NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2// priorities. Control frames like SETTINGS and PING are written before DATA// frames, but if no control frames are queued and multiple streams have queued// HEADERS or DATA frames, Pop selects a ready stream arbitrarily.//// Deprecated: User-provided write schedulers are deprecated.func () WriteScheduler {return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)}}type randomWriteScheduler struct {// zero are frames not associated with a specific stream. zero writeQueue// sq contains the stream-specific queues, keyed by stream ID. // When a stream is idle, closed, or emptied, it's deleted // from the map. sq map[uint32]*writeQueue// pool of empty queues for reuse. queuePool writeQueuePool}func ( *randomWriteScheduler) ( uint32, OpenStreamOptions) {// no-op: idle streams are not tracked}func ( *randomWriteScheduler) ( uint32) { , := .sq[]if ! {return }delete(.sq, ) .queuePool.put()}func ( *randomWriteScheduler) ( uint32, PriorityParam) {// no-op: priorities are ignored}func ( *randomWriteScheduler) ( FrameWriteRequest) {if .isControl() { .zero.push()return } := .StreamID() , := .sq[]if ! { = .queuePool.get() .sq[] = } .push()}func ( *randomWriteScheduler) () (FrameWriteRequest, bool) {// Control and RST_STREAM frames first.if !.zero.empty() {return .zero.shift(), true }// Iterate over all non-idle streams until finding one that can be consumed.for , := range .sq {if , := .consume(math.MaxInt32); {if .empty() {delete(.sq, ) .queuePool.put() }return , true } }returnFrameWriteRequest{}, false}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.