dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
PipeSink.hpp
1// SPDX-FileCopyrightText: 2025 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
14// Project includes
15#include "Sink.hpp"
16#include <dfx-fdwatch/PollerFd.hpp>
17#include <dfx-utilities/FileSystem.hpp>
18
19namespace dfx::Pcapng
20{
62class PipeSink : public Sink
63{
64public:
76 PipeSink(fs::path path, uint32_t mode = 0600);
77
83
92 void init(std::vector<uint8_t> initialHeader) override;
93
100 void setMaxQueueSize(std::size_t maxQueueSize);
101
103 std::size_t maxQueueSize() const noexcept { return _maxQueueSize; }
104
105public:
118 void write(std::vector<uint8_t> data) override;
119
120private:
121 void _handleWriteReady(FdWatch::EventTriggers events);
122
123private:
124 fs::path _pipePath;
125 FdWatch::PollerFd _fifoFd;
126
127private:
128 bool _isPipeWriteReady = true;
129 std::vector<uint8_t> _nextData;
130 std::queue<std::vector<uint8_t>> _pendingData;
131 std::size_t _maxQueueSize = 1024;
132};
133} // !namespace dfx::Pcapng
RAII wrapper for the registration of a FD in a Poller.
Definition PollerFd.hpp:42
void write(std::vector< uint8_t > data) override
Write serialized PCAPNG bytes to the FIFO.
void init(std::vector< uint8_t > initialHeader) override
Initialize the sink and write the initial PCAPNG header into the FIFO.
~PipeSink()
Destroy the sink and remove the FIFO from the filesystem.
PipeSink(fs::path path, uint32_t mode=0600)
Create a named FIFO at path.
std::size_t maxQueueSize() const noexcept
Current maximum number of queued blocks.
Definition PipeSink.hpp:103
void setMaxQueueSize(std::size_t maxQueueSize)
Set the maximum number of queued blocks when the FIFO is not writable.
Sink() noexcept=default
Construct a sink.
Definition Capture.hpp:27