5 #include <boost/asio/io_service.hpp> 6 #include <boost/asio/ip/multicast.hpp> 7 #include <boost/asio/ip/udp.hpp> 33 int main(
int argc,
char* argv[])
try {
35 cfg.load_overrides(argc, argv, std::string(
"moldheartbeat.yaml"),
"JB_ROOT");
38 boost::asio::io_service io_service;
39 boost::asio::ip::udp::resolver resolver(io_service);
40 boost::asio::ip::udp::resolver::query query(cfg.destination(), cfg.port());
42 boost::asio::ip::udp::endpoint endpoint;
43 auto i = resolver.resolve(query);
44 if (i == boost::asio::ip::udp::resolver::iterator()) {
45 JB_LOG(error) <<
"Cannot resolve destination address or port" 46 <<
", address=" << cfg.destination()
47 <<
", port=" << cfg.port();
48 throw std::runtime_error(
"cannot resolve destination address or port");
52 JB_LOG(info) <<
"Sending to endpoint=" << endpoint;
53 boost::asio::ip::udp::socket socket(io_service, endpoint.protocol());
54 socket.set_option(boost::asio::ip::multicast::enable_loopback(
true));
57 auto sink = [&socket, &endpoint](
auto buffers) {
58 socket.send_to(buffers, endpoint);
60 for (
int i = 0; i != 10000; ++i) {
62 JB_LOG(info) <<
"Sending hearbeat # " << i;
64 pacer.heartbeat(sink);
65 std::this_thread::sleep_for(std::chrono::seconds(1));
70 std::cout << u.what() << std::endl;
72 }
catch (std::exception
const& ex) {
73 std::cerr <<
"Standard exception raised: " << ex.what() << std::endl;
76 std::cerr <<
"Unknown exception raised" << std::endl;
82 std::string default_udp_port() {
86 std::string default_destination() {
93 .help(
"The destination for the UDP messages. " 94 "The destination can be a unicast or multicast address."),
95 this, default_destination())
97 desc(
"port").help(
"The destination port for the UDP messages. "),
98 this, default_udp_port())
99 , log(
desc(
"log",
"logging"),
this)
100 , pacer(
desc(
"pacer",
"mold-udp-pacer"),
this) {
103 void config::validate()
const {
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...
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.
static attribute_descriptor desc(std::string const &name)
Convenience function to create attribute descriptors with less typing.
int main(int argc, char *argv[])