dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
TcpSink.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 <memory>
13
14// Project includes
15#include "Sink.hpp"
16#include <dfx-server/TcpServerForSession.hpp>
17
18namespace dfx::Pcapng
19{
28{
29public:
31
32protected:
34 void handleMessage(std::vector<uint8_t>) override {}
35};
36
58class TcpSink : public Sink
59{
60public:
64 using ServerPtr = std::unique_ptr<Server>;
65
66public:
73 TcpSink(std::string host = "localhost", uint16_t port = 19'000);
74
75public:
83 void init(std::vector<uint8_t> initialHeader) override;
84
92 void write(std::vector<uint8_t> data) override;
93
94private:
95 Server::Options _serverOptions;
96 ServerPtr _server;
97};
98} // !namespace dfx::Pcapng
Sink() noexcept=default
Construct a sink.
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.
Server::TcpServerForSession< WriteOnlySession > Server
Server type used by this sink (write-only sessions).
Definition TcpSink.hpp:62
std::unique_ptr< Server > ServerPtr
Owning pointer to the server instance.
Definition TcpSink.hpp:64
void write(std::vector< uint8_t > data) override
Broadcast serialized PCAPNG bytes to all connected clients.
TCP session that ignores inbound traffic and is used only for streaming capture data out.
Definition TcpSink.hpp:28
void handleMessage(std::vector< uint8_t >) override
Ignore any inbound messages (capture is output-only).
Definition TcpSink.hpp:34
Convenience TcpServer that instantiates a fixed TcpSession type.
Definition TcpServerForSession.hpp:50
One asynchronous TCP connection managed by TcpServer.
Definition TcpSession.hpp:81
TcpSession(std::string host, std::string serv, TcpServer &server, std::chrono::milliseconds initialTimeout)
Construct a session descriptor (not yet bound to a socket).
Definition Capture.hpp:27
TCP server configuration.
Definition TcpServer.hpp:74