OpenDDS  Snapshot(2023/04/28-20:55)
TcpInst.h
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 #ifndef OPENDDS_DCPS_TRANSPORT_TCP_TCPINST_H
9 #define OPENDDS_DCPS_TRANSPORT_TCP_TCPINST_H
10 
11 #include "Tcp_export.h"
12 #include "TcpTransport.h"
13 
14 #include <dds/DCPS/LogAddr.h>
18 
19 #include <ace/INET_Addr.h>
20 #include <ace/SString.h>
21 
22 #include <string>
23 
24 // Forward definition of a test-friendly class in the global name space
25 class DDS_TEST;
26 
28 
29 namespace OpenDDS {
30 namespace DCPS {
31 
33  : public TransportInst {
34 public:
35 
36  static const int DEFAULT_PASSIVE_RECONNECT_DURATION = 2000;
37  static const int DEFAULT_ACTIVE_CONN_TIMEOUT_PERIOD = 5000;
38 
39  virtual int load(ACE_Configuration_Heap& cf,
41 
42  /// Diagnostic aid.
43  virtual OPENDDS_STRING dump_to_str() const;
44 
45  /// The address string provided to DCPSInfoRepo for connectors.
46  /// This string is either from configuration file or defaults
47  /// to the local address.
48  std::string pub_address_str_;
49 
51 
52  /// The initial retry delay in milliseconds.
53  /// The first connection retry will be when the loss of connection
54  /// is detected. The second try will be after this delay.
55  /// The default is 500 miliseconds.
57 
58  /// The backoff multiplier for reconnection strategy.
59  /// The third and so on reconnect will be this value * the previous delay.
60  /// Hence with conn_retry_initial_delay=500 and conn_retry_backoff_multiplier=1.5
61  /// the second reconnect attempt will be at 0.5 seconds after first retry connect
62  /// fails; the third attempt will be 0.75 seconds after the second retry connect
63  /// fails; the fourth attempt will be 1.125 seconds after the third retry connect
64  /// fails.
65  /// The default value is 2.0.
67 
68  /// Number of attempts to reconnect before giving up and calling
69  /// on_publication_lost() and on_subscription_lost() callbacks.
70  /// The default is 3.
72 
73  /// Maximum period (in milliseconds) of not being able to send queued
74  /// messages. If there are samples queued and no output for longer
75  /// than this period then the connection will be closed and on_*_lost()
76  /// callbacks will be called. If the value is zero, the default, then
77  /// this check will not be made.
79 
80  /// The time period in milliseconds for the acceptor side
81  /// of a connection to wait for the connection to be reconnected.
82  /// If not reconnected within this period then
83  /// on_publication_lost() and on_subscription_lost() callbacks
84  /// will be called.
85  /// The default is 2 seconds (2000 millseconds).
87 
88  /// The time period in milliseconds for the acceptor side
89  /// of a connection to wait for the connection to be established.
90  /// If not connected within this period then this link is removed
91  /// from pending and any other links are attempted.
92  /// The default is 5 seconds (5000 millseconds).
94 
95  bool is_reliable() const { return true; }
96 
97  /// The public address is our publicly advertised address.
98  /// Usually this is the same as the local address, but if
99  /// a public address is explicitly specified, use that.
100  const std::string& get_public_address() const {
101  return (pub_address_str_ == "") ? local_address_str_ : pub_address_str_;
102  }
103 
104  virtual size_t populate_locator(OpenDDS::DCPS::TransportLocator& trans_info, ConnectionInfoFlags flags) const;
105 
106  OPENDDS_STRING local_address_string() const { return local_address_str_; }
107  ACE_INET_Addr local_address() const { return local_address_; }
108  void local_address(const ACE_INET_Addr& addr)
109  {
110  local_address_ = addr;
111  local_address_str_ = LogAddr(addr).str();
112  }
113  void local_address(const char* str)
114  {
115  local_address_str_ = str;
116  local_address_ = choose_single_coherent_address(local_address_str_, false);
117  }
118  void local_address(u_short port_number, const char* host_name)
119  {
120  local_address_str_ = host_name;
121  local_address_str_ += ":" + to_dds_string(port_number);
122  local_address_ = choose_single_coherent_address(local_address_str_, false);
123  }
124  void local_address_set_port(u_short port_number) {
125  local_address_.set_port_number(port_number);
126  set_port_in_addr_string(local_address_str_, port_number);
127  }
128 
129 private:
130  friend class TcpType;
131  friend class TcpTransport;
132  friend class ::DDS_TEST;
133  template <typename T, typename U>
134  friend RcHandle<T> OpenDDS::DCPS::make_rch(U const&);
135  explicit TcpInst(const OPENDDS_STRING& name);
136  virtual ~TcpInst();
137 
138  TransportImpl_rch new_impl();
139 
140  /// Describes the local endpoint to be used to accept
141  /// passive connections.
143 
144  /// The address string used to configure the acceptor.
145  /// This string is either from configuration file or default
146  /// to hostname:port. The hostname is fully qualified hostname
147  /// and the port is randomly picked by os.
148  std::string local_address_str_;
149 };
150 
151 } // namespace DCPS
152 } // namespace OpenDDS
153 
155 
156 #if defined (__ACE_INLINE__)
157 #include "TcpInst.inl"
158 #endif /* __ACE_INLINE__ */
159 
160 #endif /* OPENDDS_TCPINST_H */
static int load
void local_address(const ACE_INET_Addr &addr)
Definition: TcpInst.h:108
int max_output_pause_period_
Definition: TcpInst.h:78
Base class to hold configuration settings for TransportImpls.
Definition: TransportInst.h:64
#define OpenDDS_Tcp_Export
Definition: Tcp_export.h:25
String to_dds_string(unsigned short to_convert)
RcHandle< T > make_rch()
Definition: RcHandle_T.h:256
void local_address_set_port(u_short port_number)
Definition: TcpInst.h:124
void local_address(u_short port_number, const char *host_name)
Definition: TcpInst.h:118
#define OPENDDS_STRING
bool is_reliable() const
Does the transport as configured support RELIABLE_RELIABILITY_QOS?
Definition: TcpInst.h:95
ACE_INET_Addr choose_single_coherent_address(const ACE_INET_Addr &address, bool prefer_loopback)
OPENDDS_STRING local_address_string() const
Definition: TcpInst.h:106
int active_conn_timeout_period_
Definition: TcpInst.h:93
void local_address(const char *str)
Definition: TcpInst.h:113
ACE_INET_Addr local_address() const
Definition: TcpInst.h:107
int passive_reconnect_duration_
Definition: TcpInst.h:86
const std::string & get_public_address() const
Definition: TcpInst.h:100
ACE_INET_Addr local_address_
Definition: TcpInst.h:142
double conn_retry_backoff_multiplier_
Definition: TcpInst.h:66
const char *const name
Definition: debug.cpp:60
bool enable_nagle_algorithm_
Definition: TcpInst.h:50
int conn_retry_initial_delay_
Definition: TcpInst.h:56
std::string pub_address_str_
Definition: TcpInst.h:48
const String & str() const
Definition: LogAddr.h:31
std::string local_address_str_
Definition: TcpInst.h:148
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
size_t ConnectionInfoFlags