LCOV - code coverage report
Current view: top level - envoy/tcp - async_tcp_client.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 2 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/buffer/buffer.h"
       4             : #include "envoy/network/connection.h"
       5             : 
       6             : namespace Envoy {
       7             : namespace Tcp {
       8             : 
       9             : /*
      10             :  * AsyncTcpClientOptions for the creation of async tcp client;
      11             :  */
      12             : struct AsyncTcpClientOptions {
      13           0 :   AsyncTcpClientOptions(bool enable_half_close) : enable_half_close(enable_half_close){};
      14             :   bool enable_half_close;
      15             : };
      16             : 
      17             : using AsyncTcpClientOptionsConstSharedPtr = std::shared_ptr<const AsyncTcpClientOptions>;
      18             : 
      19             : /*
      20             :  * AsyncTcpClientCallbacks for peer connection callbacks and data.
      21             :  */
      22             : class AsyncTcpClientCallbacks : public Network::ConnectionCallbacks {
      23             : public:
      24             :   ~AsyncTcpClientCallbacks() override = default;
      25             : 
      26             :   /*
      27             :    * Invoked when data is delivered from the peer connection.
      28             :    * @param data supplies data from the peer.
      29             :    * @param end_stream whether the data is the last data frame.
      30             :    */
      31             :   virtual void onData(Buffer::Instance& data, bool end_stream) PURE;
      32             : };
      33             : 
      34             : /**
      35             :  * An async TCP client with connection to peers.
      36             :  */
      37             : class AsyncTcpClient {
      38             : public:
      39           0 :   virtual ~AsyncTcpClient() = default;
      40             : 
      41             :   /**
      42             :    * Connect to a remote host. Errors or connection events are reported via the
      43             :    * event callback registered via setAsyncTcpClientCallbacks().
      44             :    */
      45             :   virtual bool connect() PURE;
      46             : 
      47             :   /**
      48             :    * Close the client. It closes the connection based on close type.
      49             :    * The underlying connection will be defer deleted when a Close event is received.
      50             :    * Abrt/NoFlush will abortively closes the connection discarding any unsent data.
      51             :    * @param type the connection close type.
      52             :    */
      53             :   virtual void close(Network::ConnectionCloseType type) PURE;
      54             : 
      55             :   /**
      56             :    * @return the detected close type from socket.
      57             :    */
      58             :   virtual Network::DetectedCloseType detectedCloseType() const PURE;
      59             : 
      60             :   /**
      61             :    * Write data through the client.
      62             :    * @param data the bufferred data.
      63             :    * @param end_stream indicates if this is the end of the stream, half close
      64             :    * should be enabled by setting end_stream to true.
      65             :    */
      66             :   virtual void write(Buffer::Instance& data, bool end_stream) PURE;
      67             : 
      68             :   /**
      69             :    * Disable socket reads on the connection, applying external back pressure.
      70             :    * @param disable supplies TRUE is reads should be disabled, FALSE if they
      71             :    * should be enabled.
      72             :    */
      73             :   virtual void readDisable(bool disable) PURE;
      74             : 
      75             :   /**
      76             :    * Add AsyncTcpClientCallbacks to the client
      77             :    * @param callbacks the client callbacks.
      78             :    */
      79             :   virtual void setAsyncTcpClientCallbacks(AsyncTcpClientCallbacks& callbacks) PURE;
      80             : 
      81             :   /**
      82             :    * @return Event::Dispatcher& the dispatcher backing this client.
      83             :    */
      84             :   virtual Event::Dispatcher& dispatcher() PURE;
      85             : 
      86             :   /**
      87             :    * @return if the client connects to a peer host.
      88             :    */
      89             :   virtual bool connected() PURE;
      90             : 
      91             :   /**
      92             :    * @return the streamInfo of the current connection if there is any.
      93             :    */
      94             :   virtual OptRef<StreamInfo::StreamInfo> getStreamInfo() PURE;
      95             : };
      96             : 
      97             : using AsyncTcpClientPtr = std::unique_ptr<AsyncTcpClient>;
      98             : 
      99             : } // namespace Tcp
     100             : } // namespace Envoy

Generated by: LCOV version 1.15