8 #include "ace/INET_Addr.h" 9 #include "ace/SOCK_Dgram.h" 17 :
Base (id, config, context)
70 int rcv_buff_size = 0;
73 "TcpTransport::setup:" \
74 " default socket buff size is send=%d, rcv=%d\n",
75 send_buff_size, rcv_buff_size);
77 if (send_buff_size < tar_buff_size)
80 "TcpTransport::setup:" \
81 " setting send buff size to settings.queue_length (%d)\n",
85 "TcpTransport::setup:" \
86 " current socket buff size is send=%d, rcv=%d\n",
87 send_buff_size, rcv_buff_size);
90 if (rcv_buff_size < tar_buff_size)
93 "TcpTransport::setup:" \
94 " setting rcv buff size to settings.queue_length (%d)\n",
98 "TcpTransport::setup:" \
99 " current socket buff size is send=%d, rcv=%d\n",
100 send_buff_size, rcv_buff_size);
118 "TcpTransportReadThread::setup:" \
124 std::stringstream thread_name;
125 thread_name <<
"read";
143 const char * print_prefix =
"TcpTransport::send_data";
149 result =
prep_send (orig_updates, print_prefix);
153 uint64_t bytes_sent = 0;
154 uint64_t packet_size = (uint64_t)result;
162 " fragmenting %" PRIu64
" byte packet (%" PRIu32
" bytes is max fragment size)\n",
168 for (FragmentMap::iterator i = map.begin (); i != map.end (); ++i)
173 for (std::map <std::string, ACE_INET_Addr>::const_iterator addr =
178 ssize_t actual_sent = -1;
185 "%s: Send result was %d of %d byte fragment to %s\n",
186 print_prefix, actual_sent, frag_size, addr->first.c_str ());
191 bytes_sent += actual_sent;
199 " Sent fragments totalling %" PRIu64
" bytes\n",
200 print_prefix, bytes_sent);
206 for (std::map <std::string, ACE_INET_Addr>::const_iterator i =
211 ssize_t actual_sent = -1;
215 " Sent %d packet to %s\n",
216 print_prefix, packet_size, i->first.c_str ());
221 bytes_sent += actual_sent;
227 result = (long)bytes_sent;
231 " Send bandwidth = %" PRIu64
" B/s\n",
QoSTransportSettings settings_
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...
threads::Threader read_threads_
threads for reading knowledge updates
void invalidate_transport(void)
Invalidates a transport to indicate it is shutting down.
long send_data(const madara::knowledge::KnowledgeRecords &updates)
Sends a list of knowledge updates to listeners.
int setup(void)
all subclasses should call this method at the end of its setup
MADARA_Export void frag(char *source, uint32_t fragment_size, FragmentMap &map)
Breaks a large packet into smaller packets.
virtual ~TcpTransport()
Destructor.
int validate_transport(void)
Validates a transport to indicate it is not shutting down.
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...
void close(void)
Closes this transport.
std::vector< std::string > hosts
Host information for transports that require it.
std::map< std::string, ACE_INET_Addr > addresses_
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
void run(const std::string name, BaseThread *thread, bool paused=false)
Starts a new thread and executes the provided user thread once.
int reliability(void) const
Accesses reliability setting.
T * get_ptr(void)
get the underlying pointer
bool no_receiving
if true, never receive over transport
::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.
const std::string id_
host:port identifier of this process
double slack_time
time to sleep between sends and rebroadcasts
TcpTransport(const std::string &id, madara::knowledge::ThreadSafeContext &context, TransportSettings &config, bool launch_transport)
Constructor.
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
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.
Thread for reading knowledge updates through a TCP socket (unused but planned)
BandwidthMonitor send_monitor_
monitor for sending bandwidth usage
madara::knowledge::ThreadSafeContext & context_
void use(ThreadSafeContext &original)
Refer to and use another knowledge base's context.