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

The simulator's command port: a small TCP server on its own thread that takes CliRequestMessages (common/control_messages.hpp) and hands each one, through a lock-free CliEndpoint, to the thread that owns what it changes. More...

#include <cli/cli_server.hpp>

Inheritance diagram for slick::sim::cli::CliServer:
Collaboration diagram for slick::sim::cli::CliServer:

Public Member Functions

 CliServer (const slick::socket::TCPServerConfig &config, std::chrono::milliseconds reply_timeout=DEFAULT_REPLY_TIMEOUT)
 ~CliServer ()
void add_endpoints (const std::string &group, const std::vector< CliEndpoint * > &endpoints)
 Routes group, and every /-prefix of each endpoint's name, to the endpoints.
void set_feeds (std::string feeds)
 What LIST_FEEDS is answered with (exch::list_feeds). Before start().
void set_version (std::string version)
 What GET_VERSION is answered with (main.cpp's SLICK_SIM_VERSION). Before start().
bool start ()
 False when the port could not be bound.
void stop ()
void flush (std::chrono::milliseconds limit)
 Waits up to limit for the replies still owed to clients to go out, so the answer to a SHUTDOWN gets sent before the server stops.
uint16_t listen_port () const noexcept
 The bound port; with a configured port of 0, the one the OS assigned.
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 uint16_t DEFAULT_PORT = 17400
static constexpr std::chrono::milliseconds DEFAULT_REPLY_TIMEOUT {2000}
static constexpr std::chrono::seconds DEFAULT_IDLE_TIMEOUT {300}
 For TCPServerConfig::idle_timeout, so dead connections can't hold every slot.

Detailed Description

The simulator's command port: a small TCP server on its own thread that takes CliRequestMessages (common/control_messages.hpp) and hands each one, through a lock-free CliEndpoint, to the thread that owns what it changes.

sim is the main thread; a venue's commands go to its order gateways' threads, which keep the state they change, so the matching loop never sees a command.

A target names a set of endpoints: a venue's config key (cme) is all of its endpoints, and every /-prefix of an endpoint's name addresses those under it (ice/<silo> is every BGW of that silo). A command goes to each endpoint of its target and is answered once all of them have, or after reply_timeout, with one line per endpoint.

A client has one request answered at a time, so its replies come in order; the rest wait in the server. A client that sends anything malformed is disconnected.

Like every slick-socket server it listens on all interfaces, with no authentication.

stop() must run before the endpoints go; the destructor does it.

Definition at line 37 of file cli_server.hpp.

Constructor & Destructor Documentation

◆ CliServer()

slick::sim::cli::CliServer::CliServer ( const slick::socket::TCPServerConfig & config,
std::chrono::milliseconds reply_timeout = DEFAULT_REPLY_TIMEOUT )
explicit

Definition at line 25 of file cli_server.cpp.

◆ ~CliServer()

slick::sim::cli::CliServer::~CliServer ( )

Definition at line 31 of file cli_server.cpp.

References stop().

Member Function Documentation

◆ add_endpoints()

void slick::sim::cli::CliServer::add_endpoints ( const std::string & group,
const std::vector< CliEndpoint * > & endpoints )

Routes group, and every /-prefix of each endpoint's name, to the endpoints.

Adding to a target that exists extends it. Before start().

Definition at line 35 of file cli_server.cpp.

References slick::sim::CliRequestMessage::target.

◆ flush()

void slick::sim::cli::CliServer::flush ( std::chrono::milliseconds limit)

Waits up to limit for the replies still owed to clients to go out, so the answer to a SHUTDOWN gets sent before the server stops.

Definition at line 79 of file cli_server.cpp.

◆ listen_port()

uint16_t slick::sim::cli::CliServer::listen_port ( ) const
inlinenodiscardnoexcept

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

Definition at line 68 of file cli_server.hpp.

◆ onClientConnected()

void slick::sim::cli::CliServer::onClientConnected ( int client_id,
const std::string & client_address )

Definition at line 86 of file cli_server.cpp.

◆ onClientData()

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

◆ onClientDisconnected()

void slick::sim::cli::CliServer::onClientDisconnected ( int client_id)

Definition at line 91 of file cli_server.cpp.

◆ onPoll()

void slick::sim::cli::CliServer::onPoll ( )

Definition at line 129 of file cli_server.cpp.

◆ set_feeds()

void slick::sim::cli::CliServer::set_feeds ( std::string feeds)
inline

What LIST_FEEDS is answered with (exch::list_feeds). Before start().

Definition at line 55 of file cli_server.hpp.

◆ set_version()

void slick::sim::cli::CliServer::set_version ( std::string version)
inline

What GET_VERSION is answered with (main.cpp's SLICK_SIM_VERSION). Before start().

Definition at line 57 of file cli_server.hpp.

◆ start()

bool slick::sim::cli::CliServer::start ( )

False when the port could not be bound.

Definition at line 66 of file cli_server.cpp.

◆ stop()

void slick::sim::cli::CliServer::stop ( )

Definition at line 75 of file cli_server.cpp.

Referenced by ~CliServer().

Member Data Documentation

◆ DEFAULT_IDLE_TIMEOUT

std::chrono::seconds slick::sim::cli::CliServer::DEFAULT_IDLE_TIMEOUT {300}
staticconstexpr

For TCPServerConfig::idle_timeout, so dead connections can't hold every slot.

Definition at line 44 of file cli_server.hpp.

Referenced by main().

◆ DEFAULT_PORT

uint16_t slick::sim::cli::CliServer::DEFAULT_PORT = 17400
staticconstexpr

Definition at line 41 of file cli_server.hpp.

Referenced by main().

◆ DEFAULT_REPLY_TIMEOUT

std::chrono::milliseconds slick::sim::cli::CliServer::DEFAULT_REPLY_TIMEOUT {2000}
staticconstexpr

Definition at line 42 of file cli_server.hpp.


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