00001 #include "orbsvcs/SSLIOP/IIOP_SSL_Connector.h"
00002
00003 #include "tao/debug.h"
00004 #include "tao/ORB_Core.h"
00005 #include "tao/IIOP_Endpoint.h"
00006 #include "tao/Transport_Cache_Manager.h"
00007 #include "tao/Thread_Lane_Resources.h"
00008 #include "tao/Connect_Strategy.h"
00009 #include "tao/Wait_Strategy.h"
00010 #include "tao/Profile_Transport_Resolver.h"
00011 #include "tao/Transport.h"
00012
00013 #include "ace/Strategies_T.h"
00014
00015
00016 ACE_RCSID (SSLIOP,
00017 IIOP_SSL_Connector,
00018 "$Id: IIOP_SSL_Connector.cpp 79388 2007-08-17 16:05:00Z wilsond $")
00019
00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00021
00022 TAO::IIOP_SSL_Connector::IIOP_SSL_Connector (void)
00023 : TAO_IIOP_Connector (),
00024 connect_strategy_ (),
00025 base_connector_ ()
00026 {
00027 }
00028
00029 TAO::IIOP_SSL_Connector::~IIOP_SSL_Connector (void)
00030 {
00031 }
00032
00033 int
00034 TAO::IIOP_SSL_Connector::open (TAO_ORB_Core *orb_core)
00035 {
00036 this->orb_core (orb_core);
00037
00038
00039 if (this->create_connect_strategy () == -1)
00040 return -1;
00041
00042
00043 CONNECT_CREATION_STRATEGY *connect_creation_strategy = 0;
00044
00045 ACE_NEW_RETURN (connect_creation_strategy,
00046 CONNECT_CREATION_STRATEGY (orb_core->thr_mgr (),
00047 orb_core),
00048 -1);
00049
00050
00051 CONNECT_CONCURRENCY_STRATEGY *concurrency_strategy = 0;
00052
00053 ACE_NEW_RETURN (concurrency_strategy,
00054 CONNECT_CONCURRENCY_STRATEGY (orb_core),
00055 -1);
00056
00057
00058 return this->base_connector_.open (this->orb_core ()->reactor (),
00059 connect_creation_strategy,
00060 &this->connect_strategy_,
00061 concurrency_strategy);
00062 }
00063
00064 int
00065 TAO::IIOP_SSL_Connector::close (void)
00066 {
00067 delete this->base_connector_.creation_strategy ();
00068 delete this->base_connector_.concurrency_strategy ();
00069 return this->base_connector_.close ();
00070 }
00071
00072 int
00073 TAO::IIOP_SSL_Connector::set_validate_endpoint (TAO_Endpoint *endpoint)
00074 {
00075 if (endpoint->tag () != IOP::TAG_INTERNET_IOP)
00076 return -1;
00077
00078 TAO_IIOP_Endpoint *iiop_endpoint =
00079 dynamic_cast<TAO_IIOP_Endpoint *> (endpoint);
00080
00081 if (iiop_endpoint == 0)
00082 return -1;
00083
00084 const ACE_INET_Addr &remote_address = iiop_endpoint->object_addr ();
00085
00086
00087
00088
00089 if (remote_address.get_type () != AF_INET)
00090 {
00091 if (TAO_debug_level > 0)
00092 {
00093 ACE_DEBUG ((LM_DEBUG,
00094 ACE_TEXT ("TAO (%P|%t) - IIOP_SSL connection failed.\n")
00095 ACE_TEXT ("TAO (%P|%t) - This is most likely ")
00096 ACE_TEXT ("due to a hostname lookup failure.\n")));
00097 }
00098
00099 return -1;
00100 }
00101
00102 return 0;
00103 }
00104
00105 TAO_Transport *
00106 TAO::IIOP_SSL_Connector::make_connection (
00107 TAO::Profile_Transport_Resolver *r,
00108 TAO_Transport_Descriptor_Interface &desc,
00109 ACE_Time_Value *max_wait_time)
00110 {
00111 TAO_IIOP_Endpoint *iiop_endpoint =
00112 dynamic_cast<TAO_IIOP_Endpoint *> (desc.endpoint ());
00113
00114 if (iiop_endpoint == 0)
00115 return 0;
00116
00117 const ACE_INET_Addr &remote_address =
00118 iiop_endpoint->object_addr ();
00119
00120 if (TAO_debug_level > 4)
00121 ACE_DEBUG ((LM_DEBUG,
00122 ACE_TEXT ("(%P|%t) IIOP_SSL_Connector::connect ")
00123 ACE_TEXT ("making a new connection \n")));
00124
00125
00126 ACE_Synch_Options synch_options;
00127
00128 this->active_connect_strategy_->synch_options (max_wait_time, synch_options);
00129
00130
00131
00132 ACE_Time_Value tmp_zero (ACE_Time_Value::zero);
00133 if (!r->blocked_connect ())
00134 {
00135 synch_options.timeout (ACE_Time_Value::zero);
00136 max_wait_time = &tmp_zero;
00137 }
00138
00139
00140 IIOP_SSL_Connection_Handler *svc_handler = 0;
00141
00142
00143 int result =
00144 this->base_connector_.connect (svc_handler, remote_address, synch_options);
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler);
00166
00167 TAO_Transport *transport =
00168 svc_handler->transport ();
00169
00170 if (result == -1)
00171 {
00172
00173 if (errno == EWOULDBLOCK)
00174 {
00175
00176
00177
00178 if (!this->wait_for_connection_completion (r,
00179 transport,
00180 max_wait_time))
00181 {
00182 if (TAO_debug_level > 2)
00183 ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::"
00184 "make_connection, "
00185 "wait for completion failed\n"));
00186 }
00187 }
00188 else
00189 {
00190
00191 transport = 0;
00192 }
00193 }
00194
00195
00196 if (transport == 0)
00197 {
00198
00199 if (TAO_debug_level)
00200 {
00201 ACE_DEBUG ((LM_ERROR,
00202 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00203 "connection to <%s:%d> failed (%p)\n",
00204 iiop_endpoint->host (), iiop_endpoint->port (),
00205 "errno"));
00206 }
00207
00208 return 0;
00209 }
00210
00211 if (transport->connection_handler ()->keep_waiting ())
00212 {
00213 svc_handler->add_reference ();
00214 }
00215
00216
00217
00218 if (TAO_debug_level > 2)
00219 ACE_DEBUG ((LM_DEBUG,
00220 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00221 "new connection to <%s:%d> on Transport[%d]\n",
00222 iiop_endpoint->host (), iiop_endpoint->port (),
00223 svc_handler->peer ().get_handle ()));
00224
00225
00226 int retval =
00227 this->orb_core ()->lane_resources ().transport_cache ().cache_transport (
00228 &desc,
00229 transport);
00230
00231
00232 if (retval != 0)
00233 {
00234
00235 svc_handler->close ();
00236
00237 if (TAO_debug_level > 0)
00238 {
00239 ACE_ERROR ((LM_ERROR,
00240 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00241 "could not add the new connection to cache\n"));
00242 }
00243
00244 return 0;
00245 }
00246
00247 if (transport->is_connected () &&
00248 transport->wait_strategy ()->register_handler () != 0)
00249 {
00250
00251
00252
00253
00254 (void) transport->purge_entry ();
00255
00256
00257 (void) transport->close_connection ();
00258
00259 if (TAO_debug_level > 0)
00260 ACE_ERROR ((LM_ERROR,
00261 "TAO (%P|%t) - IIOP_SSL_Connector [%d]::make_connection, "
00262 "could not register the transport "
00263 "in the reactor.\n",
00264 transport->id ()));
00265
00266 return 0;
00267 }
00268
00269 return transport;
00270 }
00271
00272 int
00273 TAO::IIOP_SSL_Connector::cancel_svc_handler (
00274 TAO_Connection_Handler * svc_handler)
00275 {
00276 IIOP_SSL_Connection_Handler* handler=
00277 dynamic_cast<IIOP_SSL_Connection_Handler*> (svc_handler);
00278
00279 if (handler)
00280
00281 return this->base_connector_.cancel (handler);
00282
00283 return -1;
00284 }
00285
00286 TAO_END_VERSIONED_NAMESPACE_DECL