1 /* 2 * Copyright 2014 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, version 2.0 (the 5 * "License"); you may not use this file except in compliance with the License. You may obtain a 6 * copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software distributed under the License 11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 12 * or implied. See the License for the specific language governing permissions and limitations under 13 * the License. 14 */ 15 package io.netty5.handler.codec.http2; 16 17 import io.netty5.buffer.api.Buffer; 18 import io.netty5.util.internal.UnstableApi; 19 20 /** 21 * A {@link Http2FlowController} for controlling the inbound flow of {@code DATA} frames from the remote endpoint. 22 */ 23 @UnstableApi 24 public interface Http2LocalFlowController extends Http2FlowController { 25 /** 26 * Sets the writer to be use for sending {@code WINDOW_UPDATE} frames. This must be called before any flow 27 * controlled data is received. 28 * 29 * @param frameWriter the HTTP/2 frame writer. 30 */ 31 Http2LocalFlowController frameWriter(Http2FrameWriter frameWriter); 32 33 /** 34 * Receives an inbound {@code DATA} frame from the remote endpoint and applies flow control policies to it for both 35 * the {@code stream} as well as the connection. If any flow control policies have been violated, an exception is 36 * raised immediately, otherwise the frame is considered to have "passed" flow control. 37 * <p/> 38 * If {@code stream} is {@code null} or closed, flow control should only be applied to the connection window and the 39 * bytes are immediately consumed. 40 * 41 * @param stream the subject stream for the received frame. The connection stream object must not be used. If {@code 42 * stream} is {@code null} or closed, flow control should only be applied to the connection window and the bytes are 43 * immediately consumed. 44 * @param data payload buffer for the frame. 45 * @param padding additional bytes that should be added to obscure the true content size. Must be between 0 and 46 * 256 (inclusive). 47 * @param endOfStream Indicates whether this is the last frame to be sent from the remote endpoint for this stream. 48 * @throws Http2Exception if any flow control errors are encountered. 49 */ 50 void receiveFlowControlledFrame(Http2Stream stream, Buffer data, int padding, 51 boolean endOfStream) throws Http2Exception; 52 53 /** 54 * Indicates that the application has consumed a number of bytes for the given stream and is therefore ready to 55 * receive more data from the remote endpoint. The application must consume any bytes that it receives or the flow 56 * control window will collapse. Consuming bytes enables the flow controller to send {@code WINDOW_UPDATE} to 57 * restore a portion of the flow control window for the stream. 58 * <p/> 59 * If {@code stream} is {@code null} or closed (i.e. {@link Http2Stream#state()} method returns {@link 60 * Http2Stream.State#CLOSED}), calling this method has no effect. 61 * 62 * @param stream the stream for which window space should be freed. The connection stream object must not be used. 63 * If {@code stream} is {@code null} or closed (i.e. {@link Http2Stream#state()} method returns {@link 64 * Http2Stream.State#CLOSED}), calling this method has no effect. 65 * @param numBytes the number of bytes to be returned to the flow control window. 66 * @return true if a {@code WINDOW_UPDATE} was sent, false otherwise. 67 * @throws Http2Exception if the number of bytes returned exceeds the {@link #unconsumedBytes(Http2Stream)} for the 68 * stream. 69 */ 70 boolean consumeBytes(Http2Stream stream, int numBytes) throws Http2Exception; 71 72 /** 73 * The number of bytes for the given stream that have been received but not yet consumed by the 74 * application. 75 * 76 * @param stream the stream for which window space should be freed. 77 * @return the number of unconsumed bytes for the stream. 78 */ 79 int unconsumedBytes(Http2Stream stream); 80 81 /** 82 * Get the initial flow control window size for the given stream. This quantity is measured in number of bytes. Note 83 * the unavailable window portion can be calculated by {@link #initialWindowSize()} - {@link 84 * #windowSize(Http2Stream)}. 85 */ 86 int initialWindowSize(Http2Stream stream); 87 }