OpenDDS  Snapshot(2023/04/28-20:55)
TcpTransport.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_TCPTRANSPORT_H
9 #define OPENDDS_DCPS_TRANSPORT_TCP_TCPTRANSPORT_H
10 
11 #include "Tcp_export.h"
12 #include "TcpInst_rch.h"
13 #include "TcpDataLink_rch.h"
14 #include "TcpConnection.h"
15 #include "TcpConnection_rch.h"
16 
17 #include <dds/DCPS/Atomic.h>
21 #include <dds/DCPS/TimeTypes.h>
22 
23 #include <ace/INET_Addr.h>
24 #include <ace/Hash_Map_Manager.h>
25 #include <ace/Synch_Traits.h>
26 #include <ace/Connector.h>
27 #include <ace/SOCK_Connector.h>
28 
30 
31 namespace OpenDDS {
32 namespace DCPS {
33 
34 class TcpAcceptor;
35 class TcpConnectionReplaceTask;
36 
37 /**
38  * This class provides the "Tcp" transport specific implementation.
39  * It creates the acceptor for listening the incoming requests using
40  * TCP and maintains a collection of TCP specific connections/datalinks.
41  *
42  * Notes about object ownership:
43  * 1) Own the datalink objects, passive connection objects, acceptor object
44  * and TcpConnectionReplaceTask object(used during reconnecting).
45  * 2) Reference to TransportReactorTask object owned by base class.
46  */
47 
49  : public TransportImpl
50 {
51 public:
52 
53  explicit TcpTransport(const TcpInst_rch& inst);
54  virtual ~TcpTransport();
55 
56  int fresh_link(TcpConnection_rch connection);
57 
58  virtual void unbind_link(DataLink* link);
59  TcpInst_rch config() const;
60 
61 private:
62  virtual AcceptConnectResult connect_datalink(const RemoteTransport& remote,
63  const ConnectionAttribs& attribs,
64  const TransportClient_rch& client);
65 
66  virtual AcceptConnectResult accept_datalink(const RemoteTransport& remote,
67  const ConnectionAttribs& attribs,
68  const TransportClient_rch& client);
69 
70  virtual void stop_accepting_or_connecting(const TransportClient_wrch& client,
71  const GUID_t& remote_id,
72  bool disassociate,
73  bool association_failed);
74 
75  virtual bool configure_i(const TcpInst_rch& config);
76 
77  virtual void client_stop(const GUID_t& local_id);
78 
79  virtual void shutdown_i();
80 
81  virtual bool connection_info_i(TransportLocator& local_info, ConnectionInfoFlags flags) const;
82 
83  /// Called by the DataLink to release itself.
84  virtual void release_datalink(DataLink* link);
85 
86  virtual std::string transport_type() const { return "tcp"; }
87 
88  void async_connect_failed(const PriorityKey& key);
89 
90  /// The TcpConnection is our friend. It tells us when it
91  /// has been created (by our acceptor_), and is seeking the
92  /// DataLink that should be (or will be) expecting the passive
93  /// connection.
94  friend class TcpConnection;
95  friend class TcpDataLink;
96 
97  /// Called by the TcpConnection object when it has been
98  /// created by the acceptor and needs to be attached to a DataLink.
99  /// The DataLink may or may not already be created and waiting
100  /// for this passive connection to appear.
101  void passive_connection(const ACE_INET_Addr& remote_address,
102  const TcpConnection_rch& connection);
103 
104  bool find_datalink_i(const PriorityKey& key, TcpDataLink_rch& link);
105 
106  /// Code common to make_active_connection() and
107  /// make_passive_connection().
108  int connect_tcp_datalink(TcpDataLink& link,
109  const TcpConnection_rch& connection);
110 
111  PriorityKey blob_to_key(const TransportBLOB& remote,
112  Priority priority,
113  bool active);
114 
115  /// Map Type: (key) PriorityKey to (value) TcpDataLink_rch
117  <PriorityKey,
122 
123  typedef OPENDDS_MAP(PriorityKey, TcpDataLink_rch) LinkMap;
124  typedef OPENDDS_MAP(PriorityKey, TcpConnection_rch) ConnectionMap;
125 
129 
130 // TBD SOON - Something needs to protect the tcp_config_ reference
131 // because it gets set in our configure() method, and
132 // dropped in our shutdown_i() method. Maybe we can just
133 // assume that configure() can remain unlocked (why not lock it
134 // though - it isn't in the send or receive path?)
135 // Step back and take a look at when the various locks in here
136 // get used - and if not in the direct send or receive path,
137 // maybe we can simplify this at the expense of a little more
138 // locking (ie, longer critical sections). And the base
139 // class has a lock that might work for us - check out if
140 // our base class should do the locking, and then we can
141 // assume it has been done for us (in various situations).
142 
143  /// Used to accept passive connections on our local_address_.
145 
146  class Connector : public ACE_Connector<TcpConnection, ACE_SOCK_Connector>
147  {
148  virtual int fini();
149  };
150 
151  /// Open TcpConnections using non-blocking connect.
153 
154  /// This is the map of connected DataLinks.
155  AddrLinkMap links_;
157 
158  /// This lock is used to protect the links_ data member.
159  LockType links_lock_;
160 
161  /// Map of passive connection objects that need to be paired
162  /// with a DataLink.
163  ConnectionMap connections_;
164 
165  /// This protects the connections_ and the pending_connections_
166  /// data members.
169 };
170 
171 } // namespace DCPS
172 } // namespace OpenDDS
173 
175 
176 #endif /* OPENDDS_TCPTRANSPORT_H */
AddrLinkMap links_
This is the map of connected DataLinks.
Definition: TcpTransport.h:155
#define ACE_SYNCH_MUTEX
ConditionVariable< LockType > ConditionVariableType
Definition: TcpTransport.h:128
LockType links_lock_
This lock is used to protect the links_ data member.
Definition: TcpTransport.h:159
#define OpenDDS_Tcp_Export
Definition: Tcp_export.h:25
sequence< octet > key
Encapsulate a priority value and internet address as a key.
Definition: PriorityKey.h:52
unique_ptr< TcpAcceptor > acceptor_
Used to accept passive connections on our local_address_.
Definition: TcpTransport.h:144
virtual std::string transport_type() const
Definition: TcpTransport.h:86
ACE_Guard< LockType > GuardType
Definition: TcpTransport.h:127
Atomic< size_t > last_link_
Definition: TcpTransport.h:168
int fini(void)
ACE_CDR::Long Priority
RcHandle< TcpDataLink > TcpDataLink_rch
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
Connector connector_
Open TcpConnections using non-blocking connect.
Definition: TcpTransport.h:152
AddrLinkMap pending_release_links_
Definition: TcpTransport.h:156
DDS::OctetSeq TransportBLOB
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ValueMap
Helper types and functions for config file parsing.
size_t ConnectionInfoFlags
ACE_Hash_Map_Manager_Ex< PriorityKey, TcpDataLink_rch, ACE_Hash< PriorityKey >, ACE_Equal_To< PriorityKey >, ACE_Null_Mutex > AddrLinkMap
Map Type: (key) PriorityKey to (value) TcpDataLink_rch.
Definition: TcpTransport.h:121