|
Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
|
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>
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. | |
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.
|
explicit |
Definition at line 25 of file cli_server.cpp.
| slick::sim::cli::CliServer::~CliServer | ( | ) |
Definition at line 31 of file cli_server.cpp.
References stop().
| 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.
| 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.
|
inlinenodiscardnoexcept |
The bound port; with a configured port of 0, the one the OS assigned.
Definition at line 68 of file cli_server.hpp.
| void slick::sim::cli::CliServer::onClientConnected | ( | int | client_id, |
| const std::string & | client_address ) |
Definition at line 86 of file cli_server.cpp.
| void slick::sim::cli::CliServer::onClientData | ( | int | client_id, |
| const uint8_t * | data, | ||
| size_t | length ) |
Definition at line 105 of file cli_server.cpp.
References slick::sim::CLI_REQUEST, slick::sim::ControlHeader::length, and slick::sim::ControlHeader::type.
| void slick::sim::cli::CliServer::onClientDisconnected | ( | int | client_id | ) |
Definition at line 91 of file cli_server.cpp.
| void slick::sim::cli::CliServer::onPoll | ( | ) |
Definition at line 129 of file cli_server.cpp.
|
inline |
What LIST_FEEDS is answered with (exch::list_feeds). Before start().
Definition at line 55 of file cli_server.hpp.
|
inline |
What GET_VERSION is answered with (main.cpp's SLICK_SIM_VERSION). Before start().
Definition at line 57 of file cli_server.hpp.
| bool slick::sim::cli::CliServer::start | ( | ) |
False when the port could not be bound.
Definition at line 66 of file cli_server.cpp.
| void slick::sim::cli::CliServer::stop | ( | ) |
Definition at line 75 of file cli_server.cpp.
Referenced by ~CliServer().
|
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().
|
staticconstexpr |
Definition at line 41 of file cli_server.hpp.
Referenced by main().
|
staticconstexpr |
Definition at line 42 of file cli_server.hpp.