![]() |
dfx 0.1.0
Linux-based dynamic dataflow executor
|
PCAPNG sink that streams capture bytes to a named FIFO (pipe) for live consumption. More...
#include <dfx-pcapng/sinks/PipeSink.hpp>
Public Member Functions | |
| PipeSink (fs::path path, uint32_t mode=0600) | |
Create a named FIFO at path. | |
| ~PipeSink () | |
| Destroy the sink and remove the FIFO from the filesystem. | |
| void | init (std::vector< uint8_t > initialHeader) override |
| Initialize the sink and write the initial PCAPNG header into the FIFO. | |
| void | setMaxQueueSize (std::size_t maxQueueSize) |
| Set the maximum number of queued blocks when the FIFO is not writable. | |
| std::size_t | maxQueueSize () const noexcept |
| Current maximum number of queued blocks. | |
| void | write (std::vector< uint8_t > data) override |
| Write serialized PCAPNG bytes to the FIFO. | |
| Public Member Functions inherited from dfx::Pcapng::Sink | |
| Sink () noexcept=default | |
| Construct a sink. | |
| DISABLE_COPY_AND_MOVE (Sink) | |
| Sinks are not copyable and not movable. | |
| virtual | ~Sink ()=default |
| Virtual destructor for polymorphic use. | |
| void | setPoller (FdWatch::Poller *poller) |
| Provide a poller that the sink may use for event-driven I/O. | |
Additional Inherited Members | |
| Protected Attributes inherited from dfx::Pcapng::Sink | |
| FdWatch::Poller * | _poller = nullptr |
| Borrowed poller pointer for event-driven sink implementations. | |
PCAPNG sink that streams capture bytes to a named FIFO (pipe) for live consumption.
PipeSink implements Sink by writing PCAPNG bytes to a named pipe (FIFO). The typical use-case is live capture into Wireshark: a consumer opens the FIFO for reading while dfx streams PCAPNG blocks into it.
This sink is less trivial than "just write to a pipe" because FIFOs have sharp edges:
PipeSink addresses these by integrating with a FdWatch::Poller :
Destruction removes (unlinks) the FIFO path if it had been opened successfully.
When the pipe buffer is full (EAGAIN) or the reader is absent/closed (EPIPE), the sink marks itself as "not write ready" and defers further writes until the poller signals write readiness again.
To prevent unbounded memory growth, the queue size is capped by maxQueueSize(). When the limit is reached, the oldest queued data is dropped (with a warning).
| dfx::Pcapng::PipeSink::PipeSink | ( | fs::path | path, |
| uint32_t | mode = 0600 ) |
Create a named FIFO at path.
| path | Filesystem path of the FIFO to create. |
| mode | FIFO permissions passed to mkfifo() (default: 0600). |
| dfx::Utils::Exception | Thrown if directory creation, file removal, or FIFO creation fails. |
| dfx::Pcapng::PipeSink::~PipeSink | ( | ) |
Destroy the sink and remove the FIFO from the filesystem.
If the FIFO FD was opened/attached successfully, the FIFO path is unlinked. Failures to remove the FIFO are logged.
|
overridevirtual |
Initialize the sink and write the initial PCAPNG header into the FIFO.
Opening as O_RDWR (even though this sink only writes) is intentional: opening O_WRONLY in non-blocking mode can fail with ENXIO when no reader is present.
| initialHeader | Serialized bytes that must start the PCAPNG stream. |
Implements dfx::Pcapng::Sink.
|
inlinenoexcept |
Current maximum number of queued blocks.
| void dfx::Pcapng::PipeSink::setMaxQueueSize | ( | std::size_t | maxQueueSize | ) |
Set the maximum number of queued blocks when the FIFO is not writable.
If the queue currently exceeds the new limit, the oldest queued blocks are dropped immediately until the queue fits.
| maxQueueSize | Maximum number of queued blocks. |
|
overridevirtual |
Write serialized PCAPNG bytes to the FIFO.
If the pipe is currently writable, the sink attempts to write immediately:
If the pipe is not currently writable, data is saved internally. When the queue reaches maxQueueSize(), the oldest block is dropped.
| data | Bytes to write (moved into internal storage as needed). |
Implements dfx::Pcapng::Sink.