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 79858 2007-10-25 12:58:05Z mesnier_p $")
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 #if defined (ACE_HAS_IPV6)
00091 && remote_address.get_type () != AF_INET6
00092 #endif
00093 )
00094 {
00095 if (TAO_debug_level > 0)
00096 {
00097 ACE_DEBUG ((LM_DEBUG,
00098 ACE_TEXT ("TAO (%P|%t) - IIOP_SSL connection failed.\n")
00099 ACE_TEXT ("TAO (%P|%t) - This is most likely ")
00100 ACE_TEXT ("due to a hostname lookup failure.\n")));
00101 }
00102
00103 return -1;
00104 }
00105
00106 return 0;
00107 }
00108
00109 TAO_Transport *
00110 TAO::IIOP_SSL_Connector::make_connection (
00111 TAO::Profile_Transport_Resolver *r,
00112 TAO_Transport_Descriptor_Interface &desc,
00113 ACE_Time_Value *max_wait_time)
00114 {
00115 TAO_IIOP_Endpoint *iiop_endpoint =
00116 dynamic_cast<TAO_IIOP_Endpoint *> (desc.endpoint ());
00117
00118 if (iiop_endpoint == 0)
00119 return 0;
00120
00121 const ACE_INET_Addr &remote_address =
00122 iiop_endpoint->object_addr ();
00123
00124 if (TAO_debug_level > 4)
00125 ACE_DEBUG ((LM_DEBUG,
00126 ACE_TEXT ("(%P|%t) IIOP_SSL_Connector::connect ")
00127 ACE_TEXT ("making a new connection \n")));
00128
00129
00130 ACE_Synch_Options synch_options;
00131
00132 this->active_connect_strategy_->synch_options (max_wait_time, synch_options);
00133
00134
00135
00136 ACE_Time_Value tmp_zero (ACE_Time_Value::zero);
00137 if (!r->blocked_connect ())
00138 {
00139 synch_options.timeout (ACE_Time_Value::zero);
00140 max_wait_time = &tmp_zero;
00141 }
00142
00143
00144 IIOP_SSL_Connection_Handler *svc_handler = 0;
00145
00146
00147 int result =
00148 this->base_connector_.connect (svc_handler, remote_address, synch_options);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler);
00170
00171 TAO_Transport *transport =
00172 svc_handler->transport ();
00173
00174 if (result == -1)
00175 {
00176
00177 if (errno == EWOULDBLOCK)
00178 {
00179
00180
00181
00182 if (!this->wait_for_connection_completion (r,
00183 transport,
00184 max_wait_time))
00185 {
00186 if (TAO_debug_level > 2)
00187 ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::"
00188 "make_connection, "
00189 "wait for completion failed\n"));
00190 }
00191 }
00192 else
00193 {
00194
00195 transport = 0;
00196 }
00197 }
00198
00199
00200 if (transport == 0)
00201 {
00202
00203 if (TAO_debug_level)
00204 {
00205 ACE_DEBUG ((LM_ERROR,
00206 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00207 "connection to <%s:%d> failed (%p)\n",
00208 iiop_endpoint->host (), iiop_endpoint->port (),
00209 "errno"));
00210 }
00211
00212 return 0;
00213 }
00214
00215 if (transport->connection_handler ()->keep_waiting ())
00216 {
00217 svc_handler->add_reference ();
00218 }
00219
00220
00221
00222 if (TAO_debug_level > 2)
00223 ACE_DEBUG ((LM_DEBUG,
00224 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00225 "new connection to <%s:%d> on Transport[%d]\n",
00226 iiop_endpoint->host (), iiop_endpoint->port (),
00227 svc_handler->peer ().get_handle ()));
00228
00229
00230 int retval =
00231 this->orb_core ()->lane_resources ().transport_cache ().cache_transport (
00232 &desc,
00233 transport);
00234
00235
00236 if (retval != 0)
00237 {
00238
00239 svc_handler->close ();
00240
00241 if (TAO_debug_level > 0)
00242 {
00243 ACE_ERROR ((LM_ERROR,
00244 "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, "
00245 "could not add the new connection to cache\n"));
00246 }
00247
00248 return 0;
00249 }
00250
00251 if (transport->is_connected () &&
00252 transport->wait_strategy ()->register_handler () != 0)
00253 {
00254
00255
00256
00257
00258 (void) transport->purge_entry ();
00259
00260
00261 (void) transport->close_connection ();
00262
00263 if (TAO_debug_level > 0)
00264 ACE_ERROR ((LM_ERROR,
00265 "TAO (%P|%t) - IIOP_SSL_Connector [%d]::make_connection, "
00266 "could not register the transport "
00267 "in the reactor.\n",
00268 transport->id ()));
00269
00270 return 0;
00271 }
00272
00273 return transport;
00274 }
00275
00276 int
00277 TAO::IIOP_SSL_Connector::cancel_svc_handler (
00278 TAO_Connection_Handler * svc_handler)
00279 {
00280 IIOP_SSL_Connection_Handler* handler=
00281 dynamic_cast<IIOP_SSL_Connection_Handler*> (svc_handler);
00282
00283 if (handler)
00284
00285 return this->base_connector_.cancel (handler);
00286
00287 return -1;
00288 }
00289
00290 TAO_END_VERSIONED_NAMESPACE_DECL