/proc/self/cwd/source/common/http/sidestream_watermark.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/http/async_client.h" |
4 | | |
5 | | namespace Envoy { |
6 | | namespace Http { |
7 | | |
8 | | /** |
9 | | * Sidestream watermark callback implementation for stream filter that either handles decoding only |
10 | | * or handles both encoding and decoding. |
11 | | */ |
12 | | class StreamFilterSidestreamWatermarkCallbacks : public Http::SidestreamWatermarkCallbacks { |
13 | | public: |
14 | 0 | void onSidestreamAboveHighWatermark() final { |
15 | | // Sidestream push back downstream, if callback is configured. |
16 | 0 | if (decode_callback_ != nullptr) { |
17 | 0 | decode_callback_->onDecoderFilterAboveWriteBufferHighWatermark(); |
18 | 0 | } |
19 | | |
20 | | // Sidestream push back upstream, if callback is configured. |
21 | 0 | if (encode_callback_ != nullptr) { |
22 | 0 | encode_callback_->onEncoderFilterAboveWriteBufferHighWatermark(); |
23 | 0 | } |
24 | 0 | } |
25 | | |
26 | 0 | void onSidestreamBelowLowWatermark() final { |
27 | 0 | if (decode_callback_ != nullptr) { |
28 | 0 | decode_callback_->onDecoderFilterBelowWriteBufferLowWatermark(); |
29 | 0 | } |
30 | |
|
31 | 0 | if (encode_callback_ != nullptr) { |
32 | 0 | encode_callback_->onEncoderFilterBelowWriteBufferLowWatermark(); |
33 | 0 | } |
34 | 0 | } |
35 | | |
36 | | /** |
37 | | * The set function needs to be called by stream decoder filter before side stream connection is |
38 | | * established, to apply the backpressure to downstream when it is above watermark, |
39 | | */ |
40 | 7.29k | void setDecoderFilterCallbacks(Http::StreamDecoderFilterCallbacks* decode_callback) { |
41 | 7.29k | decode_callback_ = decode_callback; |
42 | 7.29k | } |
43 | | |
44 | | /** |
45 | | * The set function needs to be called by stream encoder filter before side stream connection is |
46 | | * established, to apply the backpressure to upstream when it is above watermark, |
47 | | */ |
48 | 5.04k | void setEncoderFilterCallbacks(Http::StreamEncoderFilterCallbacks* encode_callback) { |
49 | 5.04k | encode_callback_ = encode_callback; |
50 | 5.04k | } |
51 | | |
52 | | private: |
53 | | // Non owning pointers; `removeWatermarkCallbacks()` needs to be called to unregister watermark |
54 | | // callbacks (if any) before filter callbacks are destroyed. Typically when stream is being closed |
55 | | // or filter is being destroyed. |
56 | | Http::StreamDecoderFilterCallbacks* decode_callback_ = nullptr; |
57 | | Http::StreamEncoderFilterCallbacks* encode_callback_ = nullptr; |
58 | | }; |
59 | | |
60 | | } // namespace Http |
61 | | } // namespace Envoy |