dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Core::UdpDestination Class Reference

A network destination transport using UDP with automatic fragmentation. More...

#include <dfx-core/transports/destinations/UdpDestination.hpp>

Inheritance diagram for dfx::Core::UdpDestination:
[legend]
Collaboration diagram for dfx::Core::UdpDestination:
[legend]

Public Member Functions

 UdpDestination (Endpoint endpoint, nlohmann::json config)
 Constructs a UdpDestination.
void start (FdWatch::Poller &poller) override
 Initializes the UDP socket and enables PMTUD.
void stop () noexcept override
 Closes the socket and releases resources.
bool deliver (MessagePtr message) override
 Delivers a message over the network.
Public Member Functions inherited from dfx::Core::DestinationTransport
 DestinationTransport (Endpoint endpoint, nlohmann::json config)
 Constructs a DestinationTransport with the Role::Destination role.
virtual int64_t pendingMessageCount () const noexcept
 Return the number of pending message in this transport or -1 if unknown.
Public Member Functions inherited from dfx::Core::Transport
 Transport (Role role, Endpoint endpoint, nlohmann::json config)
 Constructs a transport instance.
 DFX_DISABLE_COPY_AND_MOVE (Transport)
 Transport is not copiable nor movable.
virtual ~Transport ()=default
 Virtual destructor ensuring proper cleanup of derived transports.
template<DerivedFromTransport T>
bool is () const noexcept
 Check whether this transport is of a given derived type.
template<DerivedFromTransport T>
T & as () noexcept
 Cast this transport to a derived type (unchecked).
template<DerivedFromTransport T>
T const & as () const noexcept
 Cast this transport to a derived type (unchecked).
Role role () const noexcept
 Returns the Role (Source or Destination) of this transport.
bool isSource () const noexcept
 Returns true if this transport is a source.
bool isDestination () const noexcept
 Returns true if this transport is a destination.
Endpoint const & endpoint () const noexcept
 Gets the endpoint descriptor associated with this transport.
Channelchannel () const noexcept
 Gets the channel which this transport is attached to if any.
Portport () const noexcept
 Gets the port associated with this transport.
NodePtr node () const noexcept
 Gets the node associated with this transport.
nlohmann::json const & config () const noexcept
 Gets the JSON configuration used to initialize this transport.

Static Public Attributes

static constexpr auto defaultMtuNetworkOverhead = 64
 Prepares the UDP socket and performs initial MTU discovery.

Additional Inherited Members

Public Types inherited from dfx::Core::Transport
enum class  Role { Source , Destination }
 Defines the operational role of a transport relative to a channel. More...
Protected Attributes inherited from dfx::Core::Transport
Role const _role
Endpoint _endpoint
nlohmann::json _config

Detailed Description

A network destination transport using UDP with automatic fragmentation.

UdpDestination implements a robust "Reliable-ish" UDP transport. Because UDP does not support large payloads natively without kernel fragmentation, this class utilizes the Framer to split messages into MTU-sized frames.

Key Features
  • PMTUD: Sets IP_PMTUDISC_DO to prevent kernel-level fragmentation.
  • Dynamic MTU: Automatically updates MTU and network overhead estimates when receiving EMSGSIZE errors.
  • Vectorized I/O: Uses sendmmsg and iovec to transmit multiple frames with minimal system call overhead.
Note
The default network overhead is 64 bytes to account for IP/UDP headers.

Constructor & Destructor Documentation

◆ UdpDestination()

dfx::Core::UdpDestination::UdpDestination ( Endpoint endpoint,
nlohmann::json config )

Constructs a UdpDestination.

Parameters
endpointThe UDP endpoint (e.g., udp://127.0.0.1:5000).
configTransport-specific JSON configuration.

Member Function Documentation

◆ deliver()

bool dfx::Core::UdpDestination::deliver ( MessagePtr message)
overridevirtual

Delivers a message over the network.

This method performs the following:

  1. Packs the message into a binary buffer using Packer.
  2. Generates a unique 32-bit MessageID.
  3. Calculates the available payload size per frame: MTU - Overhead.
  4. Segments the data into a vector of mmsghdr.
  5. Executes sendmmsg.
  6. Error Recovery: If EMSGSIZE is caught, it triggers MTU re-discovery, reframes the remaining data with the new smaller size, and retries.
Parameters
messageThe message to transmit.
Returns
true if all fragments were successfully sent; false on fatal pipe errors.

Implements dfx::Core::DestinationTransport.

◆ start()

void dfx::Core::UdpDestination::start ( FdWatch::Poller & poller)
overridevirtual

Initializes the UDP socket and enables PMTUD.

Sets IP_MTU_DISCOVER to IP_PMTUDISC_DO. Fetches the initial interface MTU.

Parameters
pollerThe poller instance.

Implements dfx::Core::Transport.

◆ stop()

void dfx::Core::UdpDestination::stop ( )
overridevirtualnoexcept

Closes the socket and releases resources.

Implements dfx::Core::Transport.

Member Data Documentation

◆ defaultMtuNetworkOverhead

auto dfx::Core::UdpDestination::defaultMtuNetworkOverhead = 64
staticconstexpr

Prepares the UDP socket and performs initial MTU discovery.


The documentation for this class was generated from the following file: