dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
UdpDestination.hpp
1// SPDX-FileCopyrightText: 2026 Vincent Leroy
2// SPDX-License-Identifier: MIT
3//
4// This file is part of dfx.
5//
6// Licensed under the MIT License. See the LICENSE file in the project root
7// for full license information.
8
9#pragma once
10
11// Standard includes
12#include <queue>
13#include <random>
14
15// Project includes
16#include "DestinationTransport.hpp"
17#include <dfx-fdwatch/PollerFd.hpp>
18
19namespace dfx::Core
20{
38{
39 enum class WriteResult
40 {
41 Success,
42 Partial,
43 Queued,
44 Error,
45 };
46
47public:
49 static constexpr auto defaultMtuNetworkOverhead = 64;
50
51public:
57
58public:
65 void start(FdWatch::Poller & poller) override;
67 void stop() noexcept override;
68
83 bool deliver(MessagePtr message) override;
84
85private:
86 WriteResult _writeData(std::vector<uint8_t> data);
87 void _onSocketEvent(FdWatch::EventTriggers events);
88
89private:
90 FdWatch::PollerFd _socket;
91 FdWatch::Poller * _poller;
92 std::mt19937 _gen;
93 std::uniform_int_distribution<uint32_t> _messageIdGen;
94 uint32_t _mtu = 0;
95 uint32_t _mtuNetworkOverhead = defaultMtuNetworkOverhead;
96
97private:
98 bool _canWrite = false;
99 std::queue<std::vector<uint8_t>> _pendingData;
100};
101} // !namespace dfx::Core
DestinationTransport(Endpoint endpoint, nlohmann::json config)
Constructs a DestinationTransport with the Role::Destination role.
Definition DestinationTransport.hpp:32
Definition Endpoint.hpp:24
Endpoint const & endpoint() const noexcept
Gets the endpoint descriptor associated with this transport.
Definition Transport.hpp:161
nlohmann::json const & config() const noexcept
Gets the JSON configuration used to initialize this transport.
Definition Transport.hpp:176
bool deliver(MessagePtr message) override
Delivers a message over the network.
void stop() noexcept override
Closes the socket and releases resources.
UdpDestination(Endpoint endpoint, nlohmann::json config)
Constructs a UdpDestination.
static constexpr auto defaultMtuNetworkOverhead
Prepares the UDP socket and performs initial MTU discovery.
Definition UdpDestination.hpp:49
void start(FdWatch::Poller &poller) override
Initializes the UDP socket and enables PMTUD.
Bitset wrapper for dfx::FdWatch::EventTrigger values.
Abstract interface for FD-based event polling.
Definition Poller.hpp:37
Definition Channel.hpp:25
std::unique_ptr< Message > MessagePtr
Unique ownership handle for messages.
Definition Message.hpp:27
Definition SocketClient.hpp:23
STL namespace.