00001
00002
00003
00004
00005
00006
00007
00008 #ifndef OPENDDS_TCPCONNECTION_H
00009 #define OPENDDS_TCPCONNECTION_H
00010
00011 #include "TcpInst_rch.h"
00012 #ifdef __BORLANDC__
00013 # include "TcpDataLink.h"
00014 #endif
00015 #include "TcpDataLink_rch.h"
00016 #include "TcpConnection_rch.h"
00017 #include "TcpSendStrategy_rch.h"
00018 #include "TcpReceiveStrategy_rch.h"
00019 #include "TcpReconnectTask.h"
00020 #include "TcpTransport_rch.h"
00021
00022 #include "dds/DCPS/RcObject_T.h"
00023 #include "dds/DCPS/transport/framework/TransportDefs.h"
00024
00025 #include "ace/SOCK_Stream.h"
00026 #include "ace/Svc_Handler.h"
00027 #include "ace/INET_Addr.h"
00028 #include "ace/Synch.h"
00029
00030 namespace OpenDDS {
00031 namespace DCPS {
00032
00033 class TcpConnection
00034 : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
00035 , public RcObject<ACE_SYNCH_MUTEX> {
00036 public:
00037
00038
00039 enum ReconnectState {
00040 INIT_STATE,
00041 LOST_STATE,
00042 RECONNECTED_STATE,
00043 PASSIVE_WAITING_STATE,
00044 PASSIVE_TIMEOUT_CALLED_STATE
00045 };
00046
00047
00048 TcpConnection();
00049
00050
00051 TcpConnection(const ACE_INET_Addr& remote_address,
00052 Priority priority,
00053 const TcpInst_rch& config);
00054
00055 virtual ~TcpConnection();
00056
00057 std::size_t& id();
00058
00059
00060
00061
00062 int active_open();
00063
00064
00065
00066
00067
00068 void disconnect();
00069
00070
00071
00072 virtual int open(void* arg);
00073
00074 void set_receive_strategy(TcpReceiveStrategy* receive_strategy);
00075
00076 void remove_receive_strategy();
00077
00078
00079
00080 void set_send_strategy(TcpSendStrategy* send_strategy);
00081
00082 void remove_send_strategy();
00083
00084
00085 virtual int handle_input(ACE_HANDLE);
00086
00087
00088 virtual int handle_output(ACE_HANDLE);
00089
00090 virtual int close(u_long);
00091 virtual int handle_close(ACE_HANDLE, ACE_Reactor_Mask);
00092
00093 void set_sock_options(TcpInst* tcp_config);
00094
00095 int reconnect(bool on_new_association = false);
00096
00097
00098
00099
00100 bool is_connector() const;
00101
00102
00103 bool is_connected() const;
00104
00105 void transfer(TcpConnection* connection);
00106
00107 int handle_timeout(const ACE_Time_Value &tv, const void *arg);
00108
00109
00110
00111 void set_datalink(TcpDataLink* link);
00112
00113 void notify_lost_on_backpressure_timeout();
00114
00115 ACE_INET_Addr get_remote_address();
00116
00117
00118 void relink_from_send(bool do_suspend);
00119
00120
00121 void relink_from_recv(bool do_suspend);
00122
00123
00124
00125
00126 bool tear_link();
00127
00128 void shutdown();
00129
00130
00131 Priority& transport_priority();
00132 Priority transport_priority() const;
00133
00134 OPENDDS_POOL_ALLOCATION_FWD
00135
00136 private:
00137
00138
00139
00140
00141
00142
00143 int active_establishment(bool initiate_connect = true);
00144
00145 int active_reconnect_i();
00146 int passive_reconnect_i();
00147 int active_reconnect_on_new_association();
00148
00149
00150
00151 int handle_setup_input(ACE_HANDLE h);
00152
00153 typedef ACE_SYNCH_MUTEX LockType;
00154 typedef ACE_Guard<LockType> GuardType;
00155
00156
00157
00158 LockType reconnect_lock_;
00159
00160
00161
00162
00163 ACE_Atomic_Op<ACE_SYNCH_MUTEX, bool> connected_;
00164
00165
00166 bool is_connector_;
00167
00168
00169 TcpReceiveStrategy_rch receive_strategy_;
00170
00171
00172 TcpSendStrategy_rch send_strategy_;
00173
00174
00175 ACE_INET_Addr remote_address_;
00176
00177
00178 ACE_INET_Addr local_address_;
00179
00180
00181 TcpInst_rch tcp_config_;
00182
00183
00184 TcpDataLink_rch link_;
00185
00186
00187
00188
00189
00190 int passive_reconnect_timer_id_;
00191
00192
00193
00194
00195
00196 TcpReconnectTask reconnect_task_;
00197
00198
00199 ReconnectState reconnect_state_;
00200
00201
00202 ACE_Time_Value last_reconnect_attempted_;
00203
00204
00205 Priority transport_priority_;
00206
00207
00208 bool shutdown_;
00209
00210 bool passive_setup_;
00211 ACE_Message_Block passive_setup_buffer_;
00212 TcpTransport_rch transport_during_setup_;
00213
00214
00215 std::size_t id_;
00216 };
00217
00218 }
00219 }
00220
00221 #if defined (__ACE_INLINE__)
00222 #include "TcpConnection.inl"
00223 #endif
00224
00225 #endif