Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::md_feed::PcapControlServer Class Reference

The channel between a pcap replay and its clients, apart from the market data (multicast) and the orders (the TCP order gateway), neither of which can say that the book is still loading or ask for the replay to begin. More...

#include <md_feed/pcap_control_server.hpp>

Inheritance diagram for slick::sim::md_feed::PcapControlServer:
Collaboration diagram for slick::sim::md_feed::PcapControlServer:

Public Member Functions

 PcapControlServer (std::string name, const slick::socket::TCPServerConfig &config, std::string cli_name)
 cli_name is the CLI endpoint's (cli::pcap_feed_path).
 ~PcapControlServer ()
bool start ()
 False when the port could not be bound.
void stop ()
uint16_t listen_port () const noexcept
 The bound port; with a configured port of 0, the one the OS assigned.
void publish_status (const FeedStatusMessage &status, std::string_view message)
 Sends status to every client now connected, and to each one that connects before the next.
bool take_start () noexcept
 True once, after a client has sent START. Exchange thread.
cli::CliEndpoint & cli () noexcept
 The feed's CLI endpoint, served on the server thread while it runs.
void serve_unstarted ()
 After start() failed, so no server thread exists: serves the CLI from the calling thread, which then owns the server thread's state.
void onClientConnected (int client_id, const std::string &client_address)
void onClientDisconnected (int client_id)
void onClientData (int client_id, const uint8_t *data, size_t length)
void onPoll ()

Static Public Attributes

static constexpr size_t MAX_MESSAGE = 512
 How much of a status's message the CLI reports.

Detailed Description

The channel between a pcap replay and its clients, apart from the market data (multicast) and the orders (the TCP order gateway), neither of which can say that the book is still loading or ask for the replay to begin.

A small TCP server. A client connects, is told the current FeedStatusMessage, and is sent every later one; it sends START when it is ready for the market data. Framing is ControlHeader (common/control_messages.hpp). A client that sends anything else is disconnected.

The CLI reaches it too, through cli(): replay starts the replay as START does, and status reports the last status. The server thread serves both; when it never started, the exchange thread does, through serve_unstarted().

Threads: the server thread owns the sockets and parses what arrives; the exchange thread calls publish_status() and take_start(). Status goes through a lock-free slick::queue, which overwrites the oldest entry if the server thread falls QUEUE_SLOTS behind; START is an atomic flag.

stop() must run before destruction, as with TcpOrderGateway; the destructor does it.

Definition at line 42 of file pcap_control_server.hpp.

Constructor & Destructor Documentation

◆ PcapControlServer()

slick::sim::md_feed::PcapControlServer::PcapControlServer ( std::string name,
const slick::socket::TCPServerConfig & config,
std::string cli_name )

cli_name is the CLI endpoint's (cli::pcap_feed_path).

Definition at line 38 of file pcap_control_server.cpp.

◆ ~PcapControlServer()

slick::sim::md_feed::PcapControlServer::~PcapControlServer ( )

Definition at line 46 of file pcap_control_server.cpp.

References stop().

Member Function Documentation

◆ cli()

cli::CliEndpoint & slick::sim::md_feed::PcapControlServer::cli ( )
inlinenodiscardnoexcept

The feed's CLI endpoint, served on the server thread while it runs.

Definition at line 70 of file pcap_control_server.hpp.

◆ listen_port()

uint16_t slick::sim::md_feed::PcapControlServer::listen_port ( ) const
inlinenodiscardnoexcept

The bound port; with a configured port of 0, the one the OS assigned.

Definition at line 55 of file pcap_control_server.hpp.

◆ onClientConnected()

void slick::sim::md_feed::PcapControlServer::onClientConnected ( int client_id,
const std::string & client_address )

Definition at line 72 of file pcap_control_server.cpp.

◆ onClientData()

void slick::sim::md_feed::PcapControlServer::onClientData ( int client_id,
const uint8_t * data,
size_t length )

◆ onClientDisconnected()

void slick::sim::md_feed::PcapControlServer::onClientDisconnected ( int client_id)

Definition at line 83 of file pcap_control_server.cpp.

◆ onPoll()

void slick::sim::md_feed::PcapControlServer::onPoll ( )

Definition at line 103 of file pcap_control_server.cpp.

Referenced by serve_unstarted().

◆ publish_status()

void slick::sim::md_feed::PcapControlServer::publish_status ( const FeedStatusMessage & status,
std::string_view message )

Sends status to every client now connected, and to each one that connects before the next.

message is its message before it was cut to fit, for the CLI. The exchange thread (one producer at a time).

Definition at line 63 of file pcap_control_server.cpp.

References slick::sim::cli::cut_text().

◆ serve_unstarted()

void slick::sim::md_feed::PcapControlServer::serve_unstarted ( )
inline

After start() failed, so no server thread exists: serves the CLI from the calling thread, which then owns the server thread's state.

Each command sees the ERROR.

Definition at line 74 of file pcap_control_server.hpp.

References onPoll().

◆ start()

bool slick::sim::md_feed::PcapControlServer::start ( )

False when the port could not be bound.

Definition at line 50 of file pcap_control_server.cpp.

◆ stop()

void slick::sim::md_feed::PcapControlServer::stop ( )

Definition at line 59 of file pcap_control_server.cpp.

Referenced by ~PcapControlServer().

◆ take_start()

bool slick::sim::md_feed::PcapControlServer::take_start ( )
inlinenodiscardnoexcept

True once, after a client has sent START. Exchange thread.

Definition at line 67 of file pcap_control_server.hpp.

Member Data Documentation

◆ MAX_MESSAGE

size_t slick::sim::md_feed::PcapControlServer::MAX_MESSAGE = 512
staticconstexpr

How much of a status's message the CLI reports.

FEED_STATUS keeps its own field's size, since a longer one would break clients that read the message's length.

Definition at line 59 of file pcap_control_server.hpp.


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