| // Copyright 2026 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. |
| |
| package http2 |
| |
| // WriteScheduler is the interface implemented by HTTP/2 write schedulers. |
| // Methods are never called concurrently. |
| // |
| // Deprecated: User-provided write schedulers are deprecated. |
| type WriteScheduler interface { |
| // OpenStream opens a new stream in the write scheduler. |
| // It is illegal to call this with streamID=0 or with a streamID that is |
| // already open -- the call may panic. |
| OpenStream(streamID uint32, options OpenStreamOptions) |
| |
| // CloseStream closes a stream in the write scheduler. Any frames queued on |
| // this stream should be discarded. It is illegal to call this on a stream |
| // that is not open -- the call may panic. |
| CloseStream(streamID uint32) |
| |
| // AdjustStream adjusts the priority of the given stream. This may be called |
| // on a stream that has not yet been opened or has been closed. Note that |
| // RFC 7540 allows PRIORITY frames to be sent on streams in any state. See: |
| // https://tools.ietf.org/html/rfc7540#section-5.1 |
| AdjustStream(streamID uint32, priority PriorityParam) |
| |
| // Push queues a frame in the scheduler. In most cases, this will not be |
| // called with wr.StreamID()!=0 unless that stream is currently open. The one |
| // exception is RST_STREAM frames, which may be sent on idle or closed streams. |
| Push(wr FrameWriteRequest) |
| |
| // Pop dequeues the next frame to write. Returns false if no frames can |
| // be written. Frames with a given wr.StreamID() are Pop'd in the same |
| // order they are Push'd, except RST_STREAM frames. No frames should be |
| // discarded except by CloseStream. |
| Pop() (wr FrameWriteRequest, ok bool) |
| } |
| |
| // OpenStreamOptions specifies extra options for WriteScheduler.OpenStream. |
| // |
| // Deprecated: User-provided write schedulers are deprecated. |
| type OpenStreamOptions struct { |
| // PusherID is zero if the stream was initiated by the client. Otherwise, |
| // PusherID names the stream that pushed the newly opened stream. |
| PusherID uint32 |
| // priority is used to set the priority of the newly opened stream. |
| priority PriorityParam |
| } |
| |
| // PriorityWriteSchedulerConfig configures a priorityWriteScheduler. |
| // |
| // Deprecated: User-provided write schedulers are deprecated. |
| type PriorityWriteSchedulerConfig struct { |
| // MaxClosedNodesInTree controls the maximum number of closed streams to |
| // retain in the priority tree. Setting this to zero saves a small amount |
| // of memory at the cost of performance. |
| // |
| // See RFC 7540, Section 5.3.4: |
| // "It is possible for a stream to become closed while prioritization |
| // information ... is in transit. ... This potentially creates suboptimal |
| // prioritization, since the stream could be given a priority that is |
| // different from what is intended. To avoid these problems, an endpoint |
| // SHOULD retain stream prioritization state for a period after streams |
| // become closed. The longer state is retained, the lower the chance that |
| // streams are assigned incorrect or default priority values." |
| MaxClosedNodesInTree int |
| |
| // MaxIdleNodesInTree controls the maximum number of idle streams to |
| // retain in the priority tree. Setting this to zero saves a small amount |
| // of memory at the cost of performance. |
| // |
| // See RFC 7540, Section 5.3.4: |
| // Similarly, streams that are in the "idle" state can be assigned |
| // priority or become a parent of other streams. This allows for the |
| // creation of a grouping node in the dependency tree, which enables |
| // more flexible expressions of priority. Idle streams begin with a |
| // default priority (Section 5.3.5). |
| MaxIdleNodesInTree int |
| |
| // ThrottleOutOfOrderWrites enables write throttling to help ensure that |
| // data is delivered in priority order. This works around a race where |
| // stream B depends on stream A and both streams are about to call Write |
| // to queue DATA frames. If B wins the race, a naive scheduler would eagerly |
| // write as much data from B as possible, but this is suboptimal because A |
| // is a higher-priority stream. With throttling enabled, we write a small |
| // amount of data from B to minimize the amount of bandwidth that B can |
| // steal from A. |
| ThrottleOutOfOrderWrites bool |
| } |