MADARA  3.2.3
MulticastTransport.cpp
Go to the documentation of this file.
1 
5 
11 
12 #include <iostream>
14 
15 namespace madara { namespace transport {
16 
17 namespace mcast = ip::multicast;
18 
21  TransportSettings & config, bool launch_transport)
22 : UdpTransport (id, context, config, false)
23 {
24  if (launch_transport)
25  setup ();
26 }
27 
28 int
30  double hertz, const std::string &name)
31 {
32  read_threads_.run (hertz, name,
33  new MulticastTransportReadThread (*this));
34 
35  return 0;
36 }
37 
38 int
40 {
41  try {
42  asio::socket_base::reuse_address reuse_option(true);
43  socket_.set_option(reuse_option);
44  } catch (const boost::system::system_error &e) {
46  "MulticastTransport::setup:" \
47  " Error setting up read socket: %s\n", e.what ());
48 
49  this->invalidate_transport ();
50  return -1;
51  }
52 
54  return -1;
55  }
56 
57  try {
58  socket_.set_option (mcast::join_group (addresses_[0].address ()));
59  } catch (const boost::system::system_error &e) {
61  "MulticastTransport::setup_read_socket:" \
62  " Error subscribing: %s\n", e.what ());
63 
64  this->invalidate_transport ();
65  return -1;
66  }
67 
68  return 0;
69 }
70 
71 int
73 {
75  return -1;
76  }
77 
78  try {
79  socket_.set_option (mcast::hops (1));
80  } catch (const boost::system::system_error &e) {
82  "MulticastTransport::setup_write_socket:" \
83  " Error setting TTL: %s\n", e.what ());
84 
85  this->invalidate_transport ();
86  return -1;
87  }
88 
89  return 0;
90 }
91 
92 } }
void invalidate_transport(void)
Invalidates a transport to indicate it is shutting down.
Definition: Transport.inl:33
MulticastTransport(const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
Constructor.
int setup_read_thread(double hertz, const std::string &name) override
udp::socket socket_
underlying socket
This class stores variables and their values for use by any entity needing state information in a thr...
Thread for reading knowledge updates through a Multicast datagram socket.
Holds basic transport settings.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
Definition: Logger.h:20
void run(const std::string name, BaseThread *thread, bool paused=false)
Starts a new thread and executes the provided user thread once.
Definition: Threader.cpp:71
static struct madara::knowledge::tags::string_t string
std::vector< udp::endpoint > addresses_
holds all multicast addresses we are sending to
threads::Threader read_threads_
threads for reading knowledge updates
int setup() override
all subclasses should call this method at the end of its setup
Copyright (c) 2015 Carnegie Mellon University.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
UDP-based transport for knowledge.
Definition: UdpTransport.h:37
madara::knowledge::ThreadSafeContext & context_
Definition: Transport.h:136