1
#pragma once
2

            
3
#include "quiche/quic/core/quic_stream.h"
4

            
5
namespace Envoy {
6
namespace Quic {
7

            
8
// An interface for stream and connection to update send buffer watermark.
9
class SendBufferMonitor {
10
public:
11
14221
  virtual ~SendBufferMonitor() = default;
12

            
13
  // A scoped object to update the send buffer size change of the given quic stream to
14
  // SendBufferMonitor during its life time. If the given send buffer monitor is already monitoring,
15
  // skip updating the monitor after it's out of scope because this updater is in the scope of
16
  // another one.
17
  class ScopedWatermarkBufferUpdater {
18
  public:
19
    ScopedWatermarkBufferUpdater(quic::QuicStream* quic_stream,
20
                                 SendBufferMonitor* send_buffer_monitor);
21

            
22
    ~ScopedWatermarkBufferUpdater();
23

            
24
  private:
25
    quic::QuicStream* quic_stream_{nullptr};
26
    uint64_t old_buffered_bytes_{0};
27
    SendBufferMonitor* send_buffer_monitor_{nullptr};
28
  };
29

            
30
protected:
31
  // Update the monitor with the new buffered bytes and check watermark threshold.
32
  virtual void updateBytesBuffered(uint64_t old_buffered_bytes, uint64_t new_buffered_bytes) = 0;
33

            
34
8069
  bool isDoingWatermarkAccounting() const { return is_doing_watermark_accounting_; }
35

            
36
private:
37
  bool is_doing_watermark_accounting_{false};
38
};
39

            
40
} // namespace Quic
41
} // namespace Envoy