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

PCAPNG sink that streams capture bytes to connected clients over TCP. More...

#include <dfx-pcapng/sinks/TcpSink.hpp>

Inheritance diagram for dfx::Pcapng::TcpSink:
[legend]
Collaboration diagram for dfx::Pcapng::TcpSink:
[legend]

Public Types

using Server = Server::TcpServerForSession<WriteOnlySession>
 Server type used by this sink (write-only sessions).
using ServerPtr = std::unique_ptr<Server>
 Owning pointer to the server instance.

Public Member Functions

 TcpSink (std::string host="localhost", uint16_t port=19 '000)
 Construct a TCP sink listening on host:port.
void init (std::vector< uint8_t > initialHeader) override
 Initialize the sink and start the TCP server.
void write (std::vector< uint8_t > data) override
 Broadcast serialized PCAPNG bytes to all connected clients.
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.

Detailed Description

PCAPNG sink that streams capture bytes to connected clients over TCP.

TcpSink is a concrete Sink implementation that exposes the capture stream over a TCP server socket.

Internally it creates a dfx::Server::TcpServerForSession using a write-only session type (WriteOnlySession). Each connected client receives:

  • the initial PCAPNG header immediately upon connection.
  • then every subsequent write is broadcast to all currently connected sessions.

This sink is designed for live capture streaming to external consumers.

Lifecycle
  • init() constructs the TCP server, installs the "send header on connect" policy, and starts listening.
  • write() broadcasts data to all active sessions.
Note
By default, the sink listens on localhost:19000.

Member Typedef Documentation

◆ Server

Server type used by this sink (write-only sessions).

◆ ServerPtr

using dfx::Pcapng::TcpSink::ServerPtr = std::unique_ptr<Server>

Owning pointer to the server instance.

Constructor & Destructor Documentation

◆ TcpSink()

dfx::Pcapng::TcpSink::TcpSink ( std::string host = "localhost",
uint16_t port = 19 '000 )

Construct a TCP sink listening on host:port.

The server is not created until init() is called.

Parameters
hostHost/interface to bind to (default: "localhost").
portTCP port to listen on (default: 19000).

Member Function Documentation

◆ init()

void dfx::Pcapng::TcpSink::init ( std::vector< uint8_t > initialHeader)
overridevirtual

Initialize the sink and start the TCP server.

  • Constructs the TCP server using the poller provided via setPoller().
  • Installs a new-session callback that sends initialHeader immediately to the client.
  • Starts listening for incoming connections.
Parameters
initialHeaderSerialized PCAPNG header bytes to send to clients.

Implements dfx::Pcapng::Sink.

◆ write()

void dfx::Pcapng::TcpSink::write ( std::vector< uint8_t > data)
overridevirtual

Broadcast serialized PCAPNG bytes to all connected clients.

Iterates all current sessions and sends data to each of them. Clients that connect later will still receive the initial header from init() via the new-session callback.

Parameters
dataBytes to send.

Implements dfx::Pcapng::Sink.


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