OpenDDS  Snapshot(2023/04/28-20:55)
TcpInst.cpp
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #include "TcpInst.h"
9 
11 
12 #include <ace/Configuration.h>
13 
14 #include <iostream>
15 #include <sstream>
16 
17 #if !defined (__ACE_INLINE__)
18 #include "TcpInst.inl"
19 #endif /* __ACE_INLINE__ */
20 
22 
24 {
25  DBG_ENTRY_LVL("TcpInst","~TcpInst",6);
26 }
27 
30 {
31  return make_rch<TcpTransport>(rchandle_from(this));
32 }
33 
34 int
37 {
38  TransportInst::load(cf, trans_sect);
39 
40  std::string local_address;
41  GET_CONFIG_STRING_VALUE(cf, trans_sect, ACE_TEXT("local_address"), local_address);
42 
43  if (!local_address.empty()) {
44  this->local_address(local_address.c_str());
45  }
46 
47  GET_CONFIG_STRING_VALUE(cf, trans_sect, ACE_TEXT("pub_address"), pub_address_str_);
48 
49  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("enable_nagle_algorithm"),
50  this->enable_nagle_algorithm_, bool)
51 
52  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("conn_retry_initial_delay"),
53  this->conn_retry_initial_delay_, int)
54 
55  GET_CONFIG_DOUBLE_VALUE(cf, trans_sect, ACE_TEXT("conn_retry_backoff_multiplier"),
57 
58  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("conn_retry_attempts"),
59  this->conn_retry_attempts_, int)
60 
61  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("passive_reconnect_duration"),
62  this->passive_reconnect_duration_, int)
63 
64  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("max_output_pause_period"),
65  this->max_output_pause_period_, int)
66 
67  GET_CONFIG_VALUE(cf, trans_sect, ACE_TEXT("active_conn_timeout_period"),
68  this->active_conn_timeout_period_, int)
69 
70  return 0;
71 }
72 
75 {
76  std::ostringstream os;
78 
79  os << formatNameForDump("local_address") << this->local_address_string() << std::endl;
80  os << formatNameForDump("pub_address") << this->pub_address_str_ << std::endl;
81  os << formatNameForDump("enable_nagle_algorithm") << (this->enable_nagle_algorithm_ ? "true" : "false") << std::endl;
82  os << formatNameForDump("conn_retry_initial_delay") << this->conn_retry_initial_delay_ << std::endl;
83  os << formatNameForDump("conn_retry_backoff_multiplier") << this->conn_retry_backoff_multiplier_ << std::endl;
84  os << formatNameForDump("conn_retry_attempts") << this->conn_retry_attempts_ << std::endl;
85  os << formatNameForDump("passive_reconnect_duration") << this->passive_reconnect_duration_ << std::endl;
86  os << formatNameForDump("max_output_pause_period") << this->max_output_pause_period_ << std::endl;
87  os << formatNameForDump("active_conn_timeout_period") << this->active_conn_timeout_period_ << std::endl;
88  return OPENDDS_STRING(os.str());
89 }
90 
91 size_t
93 {
94  if (local_address() != ACE_INET_Addr() || !pub_address_str_.empty()) {
95  // Get the public address string from the inst (usually the local address)
96  NetworkResource network_resource(get_public_address());
97 
98  ACE_OutputCDR cdr;
99  cdr << network_resource;
100  const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length());
101  char* buffer = const_cast<char*>(cdr.buffer()); // safe
102 
103  local_info.transport_type = "tcp";
104  local_info.data = TransportBLOB(len, len,
105  reinterpret_cast<CORBA::Octet*>(buffer));
106  return 1;
107  } else {
108  return 0;
109  }
110 }
111 
RcHandle< T > rchandle_from(T *pointer)
Definition: RcHandle_T.h:310
virtual size_t populate_locator(OpenDDS::DCPS::TransportLocator &trans_info, ConnectionInfoFlags flags) const
Populate a transport locator sequence. Return the number of "locators.".
Definition: TcpInst.cpp:92
int max_output_pause_period_
Definition: TcpInst.h:78
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
Definition: TcpInst.cpp:35
#define GET_CONFIG_STRING_VALUE(CF, SECT, KEY, VALUE)
Definition: TransportDefs.h:76
size_t total_length(void) const
#define OPENDDS_STRING
ACE_CDR::ULong ULong
#define GET_CONFIG_VALUE(CF, SECT, KEY, VALUE, TYPE)
Definition: TransportDefs.h:45
OPENDDS_STRING local_address_string() const
Definition: TcpInst.h:106
int active_conn_timeout_period_
Definition: TcpInst.h:93
Defines a wrapper around address info which is used for advertise.
ACE_INET_Addr local_address() const
Definition: TcpInst.h:107
const char * buffer(void) const
int passive_reconnect_duration_
Definition: TcpInst.h:86
const std::string & get_public_address() const
Definition: TcpInst.h:100
double conn_retry_backoff_multiplier_
Definition: TcpInst.h:66
ACE_TEXT("TCP_Factory")
bool enable_nagle_algorithm_
Definition: TcpInst.h:50
int conn_retry_initial_delay_
Definition: TcpInst.h:56
#define GET_CONFIG_DOUBLE_VALUE(CF, SECT, KEY, VALUE)
std::string pub_address_str_
Definition: TcpInst.h:48
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
virtual OPENDDS_STRING dump_to_str() const
Diagnostic aid.
Definition: TcpInst.cpp:74
string transport_type
The transport type (e.g. tcp or udp)
static OPENDDS_STRING formatNameForDump(const char *name)
DDS::OctetSeq TransportBLOB
TransportImpl_rch new_impl()
Definition: TcpInst.cpp:29
virtual OPENDDS_STRING dump_to_str() const
size_t ConnectionInfoFlags