I'm studying some features of http2, one of them is Flow Control and want to understand that How can I implement it.
If can, give me an example or demo. Thanks.
I'm studying some features of http2, one of them is Flow Control and want to understand that How can I implement it.
If can, give me an example or demo. Thanks.
I implemented HTTP/2 in Jetty (a Java HTTP and WebSocket server), so I can point you to how it has been implemented in Jetty - but you can look at other open source projects that implement HTTP/2 and look how they have done it.
The Jetty implementation is based around class FlowControlStrategy.
There are two implementations, one naive (SimpleFlowControlStrategy) and one more efficient (BufferingFlowControlStrategy).
In both cases the FlowControlStrategy receives events from the HTTP/2 implementation, in particular:
In case of data sent to the other peer, the "send" flow control window is decreased; when a WINDOW_UPDATE frame is received from the other peer the "send" flow control window is increased.
Similarly, when data is received the "receive" flow control window is decreased; when the application consumes the received data, the "receive" flow control window is increased - and possibly a WINDOW_UPDATE frame is sent to the other peer to signal that it can send more data.
The HTTP/2 implementation needs to check these two flow control windows and stop sending data when the "send" flow control window reaches zero (or negative); and fail the connection if it receives data when the "receive" flow control window is zero (or negative). Upon receiving a a WINDOW_UPDATE frame, the HTTP/2 implementation needs to resume sending data.
This is the basic of how flow control in HTTP/2 should be implemented. Depending on the technology used and the implementation details, there are many more things to take care of such as data queuing, data copying, thread safety, etc. but you can address those while you are writing the implementation.
Have fun!