7 #include <boost/asio/io_service.hpp> 8 #include <boost/asio/ip/multicast.hpp> 9 #include <boost/asio/ip/udp.hpp> 43 boost::asio::ip::udp::socket&& s,
44 boost::asio::ip::udp::endpoint
const& ep,
46 : socket_(
std::move(s))
48 , pacer_(cfg,
jb::itch5::mold_udp_pacer<>::session_id_type(
"ITCH/RPLY")) {
54 auto sink = [
this](
auto buffers) { socket_.send_to(buffers, endpoint_); };
56 if (d > std::chrono::seconds(10)) {
58 d = std::chrono::seconds(10);
60 std::this_thread::sleep_for(d);
62 pacer_.handle_message(recv_ts, msg, sink, sleeper);
66 time_point now()
const {
67 return std::chrono::steady_clock::now();
71 boost::asio::ip::udp::socket socket_;
72 boost::asio::ip::udp::endpoint endpoint_;
78 int main(
int argc,
char* argv[])
try {
81 argc, argv, std::string(
"itch5moldreplay.yaml"),
"JB_ROOT");
84 boost::asio::io_service io_service;
85 auto address = boost::asio::ip::address::from_string(cfg.destination());
86 boost::asio::ip::udp::endpoint endpoint(address, cfg.port());
87 JB_LOG(info) <<
"Sending to endpoint=" << endpoint;
88 boost::asio::ip::udp::socket s(io_service, endpoint.protocol());
89 s.set_option(boost::asio::ip::multicast::enable_loopback(
true));
91 boost::iostreams::filtering_istream in;
94 replayer rep(std::move(s), endpoint, cfg.pacer());
95 jb::itch5::process_iostream_mlist<replayer>(in, rep);
99 std::cout << u.what() << std::endl;
101 }
catch (std::exception
const& ex) {
102 std::cerr <<
"Standard exception raised: " << ex.what() << std::endl;
105 std::cerr <<
"Unknown exception raised" << std::endl;
111 int default_multicast_port() {
115 std::string default_multicast_group() {
121 desc(
"input-file").help(
"An input file with ITCH-5.0 messages."),
125 .help(
"The destination for the UDP messages. " 126 "The destination can be a unicast or multicast address."),
127 this, default_multicast_group())
129 desc(
"port").help(
"The destination port for the UDP messages. "),
130 this, default_multicast_port())
131 , log(desc(
"log",
"logging"),
this)
132 , pacer(desc(
"pacer",
"mold-udp-pacer"),
this) {
135 void config::validate()
const {
136 if (input_file() ==
"") {
138 "Missing input-file setting." 139 " You must specify an input file.",
clock_type::time_point time_point
A convenience alias for clock_type::time_point.
Base class for all configuration objects.
virtual void validate() const
Validate the settings.
Send a sequence of raw ITCH-5.x messages as MoldUDP64 packets, trying to match the original time inte...
int main(int argc, char *argv[])
clock_type::duration duration
The duration (the difference between two time points) type.
void init(config const &cfg)
Initialize the logging functions using the configuration provided.
#define config_object_constructors(NAME)
Helper class to easily define configuration attributes.
A simple class to communicate the result of parsing the options.
Helper class to print time durations in HH:MM:SS.UUUUUU format.
void open_input_file(boost::iostreams::filtering_istream &in, std::string const &filename)
Open a file for reading.
Configuration object for the jb::itch5::mold_udp_pacer class.
The top-level namespace for the JayBeams library.