JayBeams  0.1
Another project to have fun coding.
udp_receiver_config.cpp
Go to the documentation of this file.
2 #include <jb/usage.hpp>
3 
4 #include <boost/asio/ip/udp.hpp>
5 #include <sstream>
6 
7 namespace jb {
8 namespace itch5 {
9 
11  : address(
12  desc("address").help(
13  "The destination address of the packets to receive."
14  " When receiving unicast messages this must be one of the "
15  "addresses of the host, and local_address must be empty."
16  " When receiving multicast messages this is the multicast "
17  "group of the messages to receive."),
18  this, "")
19  , port(
20  desc("port").help("The UDP port of the packets to receive."), this, 0)
21  , local_address(
22  desc("local-address")
23  .help("The local address of the receive socket."
24  " If the value of --address is a unicast address this "
25  "must be empty."
26  " If the value of --address is a multicast address this "
27  "can be one of the local addresses of the host, in which "
28  "cast that binds the socket to a specific interface to "
29  "receive the multicast messages."
30  " If the value of --address is a multicast address, and "
31  "this option is empty, the the system picks the right "
32  "ADDRANY to receive the messages."),
33  this, "") {
34 }
35 
38  if (address() == "" and port() == 0) {
39  return;
40  }
41  auto a = boost::asio::ip::address::from_string(address());
42  if (not a.is_multicast() and local_address() != "") {
43  std::ostringstream os;
44  os << "Invalid configuration for udp_receiver. --address (" << address()
45  << ") is a unicast address, and --local-address is not "
46  << "empty (" << local_address() << ")";
47  throw jb::usage(os.str(), 1);
48  }
49 }
50 
51 } // namespace itch5
52 } // namespace jb
virtual void validate() const
Validate the settings.
jb::config_attribute< udp_receiver_config, std::string > address
jb::config_attribute< udp_receiver_config, std::string > local_address
jb::config_attribute< udp_receiver_config, int > port
A simple class to communicate the result of parsing the options.
Definition: usage.hpp:11
void validate() const override
Validate the settings.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7