00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_TCPDATALINK_H 00009 #define OPENDDS_TCPDATALINK_H 00010 00011 #include "TcpConnection_rch.h" 00012 #include "TcpTransport.h" 00013 #include "dds/DCPS/transport/framework/DataLink.h" 00014 #include "ace/INET_Addr.h" 00015 00016 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace OpenDDS { 00019 namespace DCPS { 00020 00021 class TcpSendStrategy; 00022 class TcpReceiveStrategy; 00023 00024 class TcpDataLink : public DataLink { 00025 public: 00026 00027 TcpDataLink(const ACE_INET_Addr& remote_address, 00028 TcpTransport& transport_impl, 00029 Priority priority, 00030 bool is_loopback, 00031 bool is_active); 00032 virtual ~TcpDataLink(); 00033 00034 /// Accessor for the remote address. 00035 const ACE_INET_Addr& remote_address() const; 00036 00037 /// Called when an established connection object is available 00038 /// for this TcpDataLink. Called by the TcpTransport's 00039 /// connect_datalink() method. 00040 int connect(const TcpConnection_rch& connection, 00041 const RcHandle<TcpSendStrategy>& send_strategy, 00042 const RcHandle<TcpReceiveStrategy>& receive_strategy); 00043 00044 int reuse_existing_connection(const TcpConnection_rch& connection); 00045 int reconnect(const TcpConnection_rch& connection); 00046 00047 TcpConnection_rch get_connection(); 00048 00049 virtual void pre_stop_i(); 00050 00051 /// Set release pending flag. 00052 void set_release_pending(bool flag); 00053 /// Get release pending flag. 00054 bool is_release_pending() const; 00055 00056 void ack_received(const ReceivedDataSample& sample); 00057 void request_ack_received(const ReceivedDataSample& sample); 00058 void drop_pending_request_acks(); 00059 00060 TcpSendStrategy_rch send_strategy(); 00061 TcpReceiveStrategy_rch receive_strategy(); 00062 00063 protected: 00064 00065 /// Called when the DataLink is self-releasing because all of its 00066 /// reservations have been released, or when the TransportImpl is 00067 /// handling a shutdown() call. 00068 virtual void stop_i(); 00069 00070 private: 00071 bool handle_send_request_ack(TransportQueueElement* element); 00072 void send_graceful_disconnect_message(); 00073 00074 ACE_INET_Addr remote_address_; 00075 WeakRcHandle<TcpConnection> connection_; 00076 bool graceful_disconnect_sent_; 00077 ACE_Atomic_Op<ACE_Thread_Mutex, bool> release_is_pending_; 00078 typedef OPENDDS_VECTOR(TransportQueueElement*) PendingRequestAcks; 00079 ACE_SYNCH_MUTEX pending_request_acks_lock_; 00080 PendingRequestAcks pending_request_acks_; 00081 }; 00082 00083 } // namespace DCPS 00084 } // namespace OpenDDS 00085 00086 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00087 00088 #if defined (__ACE_INLINE__) 00089 #include "TcpDataLink.inl" 00090 #endif /* __ACE_INLINE__ */ 00091 00092 #endif /* OPENDDS_TCPDATALINK_H */