1
#pragma once
2

            
3
#include "envoy/buffer/buffer.h"
4
#include "envoy/common/optref.h"
5
#include "envoy/common/pure.h"
6
#include "envoy/config/core/v3/base.pb.h"
7
#include "envoy/stream_info/filter_state.h"
8

            
9
namespace Envoy {
10
namespace Extensions {
11
namespace IoSocket {
12
namespace UserSpace {
13

            
14
// Shared state between peering user space IO handles.
15
class PassthroughState {
16
public:
17
96
  virtual ~PassthroughState() = default;
18

            
19
  /**
20
   * Initialize the passthrough state from the downstream. This should be
21
   * called at most once before `mergeInto`.
22
   */
23
  virtual void initialize(std::unique_ptr<envoy::config::core::v3::Metadata> metadata,
24
                          const StreamInfo::FilterState::Objects& filter_state_objects) PURE;
25

            
26
  /**
27
   * Merge the passthrough state into a recipient stream metadata and its
28
   * filter state. This should be called at most once after `initialize`.
29
   */
30
  virtual void mergeInto(envoy::config::core::v3::Metadata& metadata,
31
                         StreamInfo::FilterState& filter_state) PURE;
32
};
33

            
34
using PassthroughStateSharedPtr = std::shared_ptr<PassthroughState>;
35
using PassthroughStatePtr = std::unique_ptr<PassthroughState>;
36

            
37
/**
38
 * The interface for the peer as a writer and supplied read status query.
39
 */
40
class IoHandle {
41
public:
42
206
  virtual ~IoHandle() = default;
43

            
44
  /**
45
   * Set the flag to indicate no further write from peer.
46
   */
47
  virtual void setWriteEnd() PURE;
48

            
49
  /**
50
   * @return true if the peer promise no more write.
51
   */
52
  virtual bool isPeerShutDownWrite() const PURE;
53

            
54
  /**
55
   * Raised when peer is destroyed. No further write to peer is allowed.
56
   */
57
  virtual void onPeerDestroy() PURE;
58

            
59
  /**
60
   * Notify that consumable data arrived. The consumable data can be either data to read, or the end
61
   * of stream event.
62
   */
63
  virtual void setNewDataAvailable() PURE;
64

            
65
  /**
66
   * @return the buffer to be written.
67
   */
68
  virtual Buffer::Instance* getWriteBuffer() PURE;
69

            
70
  /**
71
   * @return true if more data is acceptable at the destination buffer.
72
   */
73
  virtual bool isWritable() const PURE;
74

            
75
  /**
76
   * @return true if peer is valid and writable.
77
   */
78
  virtual bool isPeerWritable() const PURE;
79

            
80
  /**
81
   * Raised by the peer when the peer switch from high water mark to low.
82
   */
83
  virtual void onPeerBufferLowWatermark() PURE;
84

            
85
  /**
86
   * @return true if the pending receive buffer is not empty or read_end is set.
87
   */
88
  virtual bool isReadable() const PURE;
89

            
90
  /**
91
   * @return shared state between peering user space IO handles.
92
   */
93
  virtual PassthroughStateSharedPtr passthroughState() PURE;
94
};
95
} // namespace UserSpace
96
} // namespace IoSocket
97
} // namespace Extensions
98
} // namespace Envoy