13 :
Base (id, config, context)
66 for (
unsigned int i = 0; i <
addresses_.size (); ++i)
71 "BroadcastTransport::constructor" \
72 " settings address[%d] to %s:%d\n", i,
77 if (
socket_.open (ACE_Addr::sap_any) == -1)
80 "BroadcastTransport::constructor" \
81 "socket failed to open\n");
86 int rcv_buff_size = 0;
87 int opt_len =
sizeof (int);
89 socket_.get_option (SOL_SOCKET, SO_SNDBUF,
90 (
void *)&send_buff_size, &opt_len);
92 socket_.get_option (SOL_SOCKET, SO_RCVBUF,
93 (
void *)&rcv_buff_size, &opt_len);
96 "BroadcastTransport::constructor" \
97 " default socket buff size is send=%d, rcv=%d\n",
98 send_buff_size, rcv_buff_size);
100 if (send_buff_size < tar_buff_size)
103 "BroadcastTransport::constructor" \
104 " setting send buff size to settings.queue_length (%d)\n",
107 socket_.set_option (SOL_SOCKET, SO_SNDBUF,
108 (
void *)&tar_buff_size, opt_len);
110 socket_.get_option (SOL_SOCKET, SO_SNDBUF,
111 (
void *)&send_buff_size, &opt_len);
114 "BroadcastTransport::constructor" \
115 " current socket buff size is send=%d, rcv=%d\n",
116 send_buff_size, rcv_buff_size);
119 if (rcv_buff_size < tar_buff_size)
122 "BroadcastTransport::constructor" \
123 " setting rcv buff size to settings.queue_length (%d)\n",
126 socket_.set_option (SOL_SOCKET, SO_RCVBUF,
127 (
void *)&tar_buff_size, opt_len);
129 socket_.get_option (SOL_SOCKET, SO_RCVBUF,
130 (
void *)&rcv_buff_size, &opt_len);
133 "BroadcastTransport::constructor" \
134 " current socket buff size is send=%d, rcv=%d\n",
135 send_buff_size, rcv_buff_size);
148 "BroadcastTransport::constructor:" \
154 std::stringstream thread_name;
155 thread_name <<
"read";
174 const char * print_prefix =
"BroadcastTransport::send_data";
179 result =
prep_send (orig_updates, print_prefix);
183 uint64_t bytes_sent = 0;
184 uint64_t packet_size = (uint64_t)result;
192 " fragmenting %" PRIu64
" byte packet (%" PRIu32
" bytes is max fragment size)\n",
199 for (FragmentMap::iterator i = map.begin (); i != map.end (); ++i, ++j)
203 " Sending fragment %d\n",
206 int send_attempts = -1;
207 ssize_t actual_sent = -1;
209 while (actual_sent < 0 &&
226 " Sent %d byte fragment\n",
227 print_prefix, (int)actual_sent);
229 bytes_sent += actual_sent;
235 " Send fragment failed, socket busy\n", print_prefix);
251 " Sent fragments totalling %" PRIu64
" bytes\n",
252 print_prefix, bytes_sent);
260 " Sending packet of size %ld\n",
261 print_prefix, result);
263 int send_attempts = -1;
264 ssize_t actual_sent = -1;
266 while (actual_sent < 0 &&
279 bytes_sent = (uint64_t)actual_sent;
283 " Sent packet of size %" PRIu64
"\n",
284 print_prefix, bytes_sent);
288 else if (actual_sent == ECONNRESET)
292 " WARNING: Remote socket disappeared during send (ECONNRESET)\n",
295 else if (actual_sent == EINTR)
299 " Local socket was interrupted during send (EINTR)\n",
302 else if (actual_sent == EWOULDBLOCK)
306 " Send would have blocked (EWOULDBLOCK)\n",
309 else if (actual_sent == ENOTCONN)
313 " Send reports socket is not connected (ENOTCONN)\n",
316 else if (actual_sent == EADDRINUSE)
320 " Send reports the interface is busy (EADDRINUSE)\n",
323 else if (actual_sent == EBADF)
327 " Send socket is invalid (EBADF)\n",
334 " Packet was not sent due to unknown error (%d)\n",
335 print_prefix, (int)actual_sent);
342 " Send bandwidth = %" PRIu64
" B/s\n",
345 result = (long) bytes_sent;
Thread for reading knowledge updates through a Multicast datagram socket.
QoSTransportSettings settings_
void close(void)
Closes the transport.
long prep_send(const madara::knowledge::KnowledgeRecords &orig_updates, const char *print_prefix)
Preps a message for sending.
uint64_t get_bytes_per_second(void)
Queries the monitor for the current bandwidth utilization per second over the past window...
void invalidate_transport(void)
Invalidates a transport to indicate it is shutting down.
int setup(void)
Initializes the transport.
MADARA_Export void frag(char *source, uint32_t fragment_size, FragmentMap &map)
Breaks a large packet into smaller packets.
int validate_transport(void)
Validates a transport to indicate it is not shutting down.
int reliability(void) const
Accesses reliability setting.
threads::Threader read_threads_
threads for reading knowledge updates
knowledge::KnowledgeBase knowledge_
knowledge base for threads to use
This class stores variables and their values for use by any entity needing state information in a thr...
std::vector< std::string > hosts
Host information for transports that require it.
virtual ~BroadcastTransport()
Destructor.
double read_thread_hertz
number of valid messages allowed to be received per second.
MADARA_Export double sleep(double sleep_time)
Sleeps for a certain amount of time.
Holds basic transport settings.
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
BandwidthMonitor receive_monitor_
monitor for receiving bandwidth usage
ACE_SOCK_Dgram_Bcast socket_
underlying socket for sending
void run(const std::string name, BaseThread *thread, bool paused=false)
Starts a new thread and executes the provided user thread once.
T * get_ptr(void)
get the underlying pointer
bool no_receiving
if true, never receive over transport
BroadcastTransport(const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
Constructor.
::std::map< std::string, KnowledgeRecord * > KnowledgeRecords
bool no_sending
if true, never send over transport
void add(uint64_t size)
Adds a message to the monitor.
long send_data(const madara::knowledge::KnowledgeRecords &updates)
Sends a list of knowledge updates to listeners.
const std::string id_
host:port identifier of this process
double slack_time
time to sleep between sends and rebroadcasts
MADARA_Export void delete_fragments(FragmentMap &map)
Deletes fragments within a fragment map and clears the map.
uint32_t read_threads
the number of read threads to start
uint32_t queue_length
Length of the buffer used to store history of events.
void terminate(const std::string name)
Requests a specific thread to terminate.
std::map< uint32_t, const char * > FragmentMap
Map of fragment identifiers to fragments.
PacketScheduler packet_scheduler_
scheduler for dropping packets to simulate network issues
std::vector< ACE_INET_Addr > addresses_
holds all multicast addresses we are sending to
madara::utility::ScopedArray< char > buffer_
buffer for sending
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
virtual int setup(void)
all subclasses should call this method at the end of its setup
void set_data_plane(knowledge::KnowledgeBase &data_plane)
Sets the data plane for new threads.
Base class from which all transports must be derived.
uint32_t max_fragment_size
Maximum allowed fragment size for partitioning large messages.
bool wait(const std::string name, const knowledge::WaitSettings &ws=knowledge::WaitSettings())
Wait for a specific thread to complete.
BandwidthMonitor send_monitor_
monitor for sending bandwidth usage
madara::knowledge::ThreadSafeContext & context_
int resend_attempts
Maximum number of attempts to resend if transport is busy.
void use(ThreadSafeContext &original)
Refer to and use another knowledge base's context.