Repository: envoyproxy/envoy
File: envoy/network/udp_packet_writer_handler.h (C/C++)

Code before:
   * @brief Batch Mode: Try to send all buffered packets
   *        PassThrough Mode: NULL operation
   *
   * @return Api::IoCallUint64Result
   */
  virtual Api::IoCallUint64Result flush() PURE;
};

using UdpPacketWriterPtr = std::unique_ptr<UdpPacketWriter>;

class UdpPacketWriterFactory {
public:
  virtual ~UdpPacketWriterFactory() = default;

  /**
   * Creates an UdpPacketWriter object for the given Udp Socket
   * @param socket UDP socket used to send packets.
   * @return the UdpPacketWriter created.
   */
  virtual UdpPacketWriterPtr
  createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope,
                        Envoy::Event::Dispatcher& dispatcher,
                        absl::AnyInvocable<void() &&> on_can_write_cb) PURE;
};

using UdpPacketWriterFactoryPtr = std::unique_ptr<UdpPacketWriterFactory>;

/**
 * UdpPacketWriterFactoryFactory adds an extra layer of indirection In order to
 * support a UdpPacketWriterFactory whose behavior depends on the
 * TypedConfig for that factory. The UdpPacketWriterFactoryFactory is created
 * with a no-arg constructor based on the type of the config. Then this
 * `createUdpPacketWriterFactory1 can be called with the config to
 * create an actual UdpPacketWriterFactory.
 */
class UdpPacketWriterFactoryFactory : public Envoy::Config::TypedFactory {
public:
  ~UdpPacketWriterFactoryFactory() override = default;

  /**
   * Creates an UdpPacketWriterFactory based on the specified config.
   * @return the UdpPacketWriterFactory created.
   */
  virtual UdpPacketWriterFactoryPtr
  createUdpPacketWriterFactory(const envoy::config::core::v3::TypedExtensionConfig& config) PURE;

  std::string category() const override { return "envoy.udp_packet_writer"; }
};

} // namespace Network
} // namespace Envoy

Review comment (suggestion):
Please add comments for the new parameters (`dispacter` is pretty obvious, but `on_can_write_cb` is less so)

Code after:
   * @brief Batch Mode: Try to send all buffered packets
   *        PassThrough Mode: NULL operation
   *
   * @return Api::IoCallUint64Result
   */
  virtual Api::IoCallUint64Result flush() PURE;
};

using UdpPacketWriterPtr = std::unique_ptr<UdpPacketWriter>;

class UdpPacketWriterFactory {
public:
  virtual ~UdpPacketWriterFactory() = default;

  /**
   * Creates an UdpPacketWriter object for the given Udp Socket
   * @param io_handle The udp socket used for network I/O operations.
   * @param scope Recording statistics associated with the writer.
   * @param dispatcher Envoy dispatcher to schedule write block events.
   * @param on_can_write_cb Callback to signal when the underlying socket
   * becomes writable.
   * @return the UdpPacketWriter created.
   */
  virtual UdpPacketWriterPtr
  createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope,
                        Envoy::Event::Dispatcher& dispatcher,
                        absl::AnyInvocable<void() &&> on_can_write_cb) PURE;
};

using UdpPacketWriterFactoryPtr = std::unique_ptr<UdpPacketWriterFactory>;

/**
 * UdpPacketWriterFactoryFactory adds an extra layer of indirection In order to
 * support a UdpPacketWriterFactory whose behavior depends on the
 * TypedConfig for that factory. The UdpPacketWriterFactoryFactory is created
 * with a no-arg constructor based on the type of the config. Then this
 * `createUdpPacketWriterFactory1 can be called with the config to
 * create an actual UdpPacketWriterFactory.
 */
class UdpPacketWriterFactoryFactory : public Envoy::Config::TypedFactory {
public:
  ~UdpPacketWriterFactoryFactory() override = default;

  /**
   * Creates an UdpPacketWriterFactory based on the specified config.
   * @return the UdpPacketWriterFactory created.
   */
  virtual UdpPacketWriterFactoryPtr
  createUdpPacketWriterFactory(const envoy::config::core::v3::TypedExtensionConfig& config) PURE;

  std::string category() const override { return "envoy.udp_packet_writer"; }