diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2004-08-09 11:53:16 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2004-08-09 11:53:16 +0000 |
commit | 5eab0611201c153800002942b0bd5d06743085a5 (patch) | |
tree | 9db9c40b62eb2bf93e31f5fbf3a479f450148a10 /TAO/orbsvcs/orbsvcs/SSLIOP | |
parent | 659b1d7d4d4d401cff367f8d6e53f07eaf75057a (diff) | |
download | ATCD-5eab0611201c153800002942b0bd5d06743085a5.tar.gz |
ChangeLogTag: Mon Aug 9 11:51:12 UTC 2004 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/orbsvcs/orbsvcs/SSLIOP')
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp | 174 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.h | 2 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp | 11 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp | 191 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.h | 3 |
5 files changed, 172 insertions, 209 deletions
diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp index a13d41276d7..b2c65d931e1 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.cpp @@ -10,6 +10,7 @@ #include "tao/Thread_Lane_Resources.h" #include "tao/Connect_Strategy.h" #include "tao/Wait_Strategy.h" +#include "tao/Profile_Transport_Resolver.h" #include "ace/Strategies_T.h" @@ -125,7 +126,7 @@ TAO::IIOP_SSL_Connector::set_validate_endpoint (TAO_Endpoint *endpoint) if (TAO_debug_level > 0) { ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) IIOP connection failed.\n") + ACE_TEXT ("TAO (%P|%t) IIOP_SSL connection failed.\n") ACE_TEXT ("TAO (%P|%t) This is most likely ") ACE_TEXT ("due to a hostname lookup ") ACE_TEXT ("failure.\n"))); @@ -139,7 +140,7 @@ TAO::IIOP_SSL_Connector::set_validate_endpoint (TAO_Endpoint *endpoint) TAO_Transport * TAO::IIOP_SSL_Connector::make_connection ( - TAO::Profile_Transport_Resolver *, + TAO::Profile_Transport_Resolver *r, TAO_Transport_Descriptor_Interface &desc, ACE_Time_Value *max_wait_time) { @@ -163,6 +164,16 @@ TAO::IIOP_SSL_Connector::make_connection ( this->active_connect_strategy_->synch_options (max_wait_time, synch_options); + // If we don't need to block for a transport just set the timeout to + // be zero. + ACE_Time_Value tmp_zero (ACE_Time_Value::zero); + if (!r->blocked ()) + { + synch_options.timeout (ACE_Time_Value::zero); + max_wait_time = &tmp_zero; + } + + IIOP_SSL_Connection_Handler *svc_handler = 0; // Connect. @@ -189,97 +200,45 @@ TAO::IIOP_SSL_Connector::make_connection ( // another thread pick up the completion and potentially deletes the // handler before we get a chance to increment the reference count. - // No immediate result. Wait for completion. - if (result == -1 && errno == EWOULDBLOCK) - { - if (TAO_debug_level) - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - IIOP_SSL_Connector::make_connection(), " - "going to wait for connection completion on local" - "handle [%d]\n", - svc_handler->get_handle ())); - - // Wait for connection completion. No need to specify timeout - // to wait() since the correct timeout was passed to the - // Connector. The Connector will close the handler in the case - // of timeouts, so the event will complete (either success or - // failure) within timeout. - result = - this->active_connect_strategy_->wait (svc_handler, - 0); - - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - IIOP_SSL_Connector::make_connection(), " - "wait done for handle[%d], result = %d\n", - svc_handler->get_handle (), result)); - } - - // There are three possibilities when wait() returns: (a) - // connection succeeded; (b) connection failed; (c) wait() - // failed because of some other error. It is easy to deal with - // (a) and (b). (c) is tricky since the connection is still - // pending and may get completed by some other thread. The - // following code deals with (c). + // Make sure that we always do a remove_reference + ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler); - // Check if the handler has been closed. - int closed = - svc_handler->is_closed (); + TAO_Transport *transport = + svc_handler->transport (); - // In case of failures and close() has not be called. - if (result == -1 && - !closed) + if (result == -1) + { + // No immediate result, wait for completion + if (errno == EWOULDBLOCK) { - // First, cancel from connector. - this->base_connector_.cancel (svc_handler); - - // Double check to make sure the handler has not been closed - // yet. This double check is required to ensure that the - // connection handler was not closed yet by some other - // thread since it was still registered with the connector. - // Once connector.cancel() has been processed, we are - // assured that the connector will no longer open/close this - // handler. - closed = - svc_handler->is_closed (); - - // If closed, there is nothing to do here. If not closed, - // it was either opened or is still pending. - if (!closed) + // Try to wait until connection completion. Incase we block, then we + // get a connected transport or not. In case of non block we get + // a connected or not connected transport + if (!this->wait_for_connection_completion (r, + transport, + max_wait_time)) { - // Check if the handler has been opened. - int open = - svc_handler->is_open (); - - // Some other thread was able to open the handler even - // though wait failed for this thread. - if (open) - // Overwrite <result>. - result = 0; - else - { - // Assert that it is still connecting. - ACE_ASSERT (svc_handler->is_connecting ()); - - // Force close the handler now. - svc_handler->close (); - } + if (TAO_debug_level > 2) + ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::" + "make_connection, " + "wait for completion failed\n")); } } + else + { + // Transport is not usable + transport = 0; + } } - // Irrespective of success or failure, remove the extra #REFCOUNT#. - svc_handler->remove_reference (); - - // In case of errors. - if (result == -1) + // In case of errors transport is zero + if (transport == 0) { // Give users a clue to the problem. if (TAO_debug_level) { ACE_DEBUG ((LM_ERROR, - "TAO (%P|%t) - IIOP_Connector::make_connection, " + "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, " "connection to <%s:%d> failed (%p)\n", iiop_endpoint->host (), iiop_endpoint->port (), "errno")); @@ -292,14 +251,11 @@ TAO::IIOP_SSL_Connector::make_connection ( // #REFCOUNT# is one. if (TAO_debug_level > 2) ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - IIOP_Connector::make_connection, " + "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, " "new connection to <%s:%d> on Transport[%d]\n", iiop_endpoint->host (), iiop_endpoint->port (), svc_handler->peer ().get_handle ())); - TAO_Transport *transport = - svc_handler->transport (); - // Add the handler to Cache int retval = this->orb_core ()->lane_resources ().transport_cache ().cache_transport ( @@ -315,36 +271,54 @@ TAO::IIOP_SSL_Connector::make_connection ( if (TAO_debug_level > 0) { ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - IIOP_Connector::make_connection, " + "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, " "could not add the new connection to cache\n")); } return 0; } - // If the wait strategy wants us to be registered with the reactor - // then we do so. If registeration is required and it succeeds, - // #REFCOUNT# becomes two. - retval = transport->wait_strategy ()->register_handler (); - - // Registration failures. - if (retval != 0) + if (transport->is_connected () && + transport->wait_strategy ()->register_handler () != 0) { - // Purge from the connection cache. - transport->purge_entry (); + // Registration failures. + + // Purge from the connection cache, if we are not in the cache, this + // just does nothing. + (void) transport->purge_entry (); // Close the handler. - svc_handler->close (); + (void) transport->close_connection (); if (TAO_debug_level > 0) - { - ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - IIOP_Connector::make_connection, " - "could not register the new connection in the reactor\n")); - } + ACE_ERROR ((LM_ERROR, + "TAO (%P|%t) - IIOP_SSL_Connector [%d]::make_connection, " + "could not register the transport " + "in the reactor.\n", + transport->id ())); return 0; } return transport; } + +int +TAO::IIOP_SSL_Connector::cancel_svc_handler ( + TAO_Connection_Handler * svc_handler) +{ + IIOP_SSL_Connection_Handler* handler= + dynamic_cast<IIOP_SSL_Connection_Handler*>(svc_handler); + + if (handler) + { + // Cancel from the connector + this->base_connector_.cancel (handler); + + return 0; + } + else + { + return -1; + } +} diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.h b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.h index 24f4481fc61..ab1b6449ec6 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.h +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/IIOP_SSL_Connector.h @@ -81,6 +81,8 @@ namespace TAO TAO_Transport *make_connection (TAO::Profile_Transport_Resolver *r, TAO_Transport_Descriptor_Interface &desc, ACE_Time_Value *timeout = 0); + + virtual int cancel_svc_handler (TAO_Connection_Handler * svc_handler); //@} private: diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp index 6660602351c..1d11ea6eb0d 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp @@ -164,10 +164,11 @@ TAO::SSLIOP::Connection_Handler::open (void *) this->peer ().get_handle ())); } - // Set the id in the transport now that we're active. + // Set that the transport is now connected, if fails we return -1 // Use C-style cast b/c otherwise we get warnings on lots of - // compilers. - this->transport ()->id ((size_t) this->get_handle ()); + // compilers + if (!this->transport ()->post_open ((size_t) this->get_handle ())) + return -1; // @@ Not needed this->state_changed (TAO_LF_Event::LFS_SUCCESS); @@ -238,9 +239,7 @@ TAO::SSLIOP::Connection_Handler::handle_close (ACE_HANDLE, int TAO::SSLIOP::Connection_Handler::close (u_long) { - this->state_changed (TAO_LF_Event::LFS_CONNECTION_CLOSED); - this->transport ()->remove_reference (); - return 0; + return this->close_handler (); } int diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp index cc2f125e75a..f38b37ef4bc 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.cpp @@ -126,7 +126,7 @@ TAO::SSLIOP::Connector::connect (TAO::Profile_Transport_Resolver *resolver, { if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("TAO (%P|%t) Connector::connect - ") + ACE_TEXT ("TAO (%P|%t) - Connector::connect, ") ACE_TEXT ("looking for SSLIOP connection.\n"))); TAO_Endpoint *endpoint = desc->endpoint (); @@ -411,15 +411,29 @@ TAO::SSLIOP::Connector::ssliop_connect ( { if (TAO_debug_level > 2) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) SSLIOP_Connector::connect ") + ACE_TEXT ("TAO (%P|%t) - SSLIOP_Connector::ssliop_connect, ") ACE_TEXT ("got existing transport[%d]\n"), transport->id ())); + + // When the transport is not connected wait for completion + if (!transport->is_connected()) + { + if (!this->wait_for_connection_completion (resolver, + transport, + max_wait_time)) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("TAO (%P|%t) - SSLIOP_Connector::ssliop_connect,") + ACE_TEXT ("wait for completion failed\n"))); + + } + } } else { if (TAO_debug_level > 4) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) SSLIOP_Connector::connect ") + ACE_TEXT ("TAO (%P|%t) - SSLIOP_Connector::ssliop_connect, ") ACE_TEXT ("making a new connection \n"))); // Purge connections (if necessary) @@ -447,7 +461,7 @@ TAO::SSLIOP::Connector::ssliop_connect ( { if (TAO_debug_level > 0) ACE_DEBUG ((LM_ERROR, - ACE_TEXT ("(%P|%t) Unable to create SSLIOP ") + ACE_TEXT ("TAO (%P|%t) Unable to create SSLIOP ") ACE_TEXT ("service handler.\n"))); return 0; @@ -515,6 +529,15 @@ TAO::SSLIOP::Connector::ssliop_connect ( this->active_connect_strategy_->synch_options (max_wait_time, synch_options); + // If we don't need to block for a transport just set the timeout to + // be zero. + ACE_Time_Value tmp_zero (ACE_Time_Value::zero); + if (!resolver->blocked ()) + { + synch_options.timeout (ACE_Time_Value::zero); + max_wait_time = &tmp_zero; + } + // We obtain the transport in the <svc_handler> variable. As we // know now that the connection is not available in Cache we can // make a new connection @@ -530,91 +553,39 @@ TAO::SSLIOP::Connector::ssliop_connect ( // the #REFCOUNT# on the handler is one since close() gets // called on the handler. - // No immediate result. Wait for completion. - if (result == -1 && errno == EWOULDBLOCK) - { - if (TAO_debug_level > 2) - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - SSLIOP_Connector::ssliop_connect(), " - "going to wait for connection completion on local" - "handle [%d]\n", - svc_handler->get_handle ())); - - // Wait for connection completion. No need to specify timeout - // to wait() since the correct timeout was passed to the - // Connector. The Connector will close the handler in the case - // of timeouts, so the event will complete (either success or - // failure) within timeout. - result = - this->active_connect_strategy_->wait (svc_handler, - 0); - - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - IIOP_Connector::make_connection" - "wait done for handle[%d], result = %d\n", - svc_handler->get_handle (), result)); - } - - // There are three possibilities when wait() returns: (a) - // connection succeeded; (b) connection failed; (c) wait() - // failed because of some other error. It is easy to deal with - // (a) and (b). (c) is tricky since the connection is still - // pending and may get completed by some other thread. The - // following code deals with (c). + // Make sure that we always do a remove_reference + ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler); - // Check if the handler has been closed. - int closed = - svc_handler->is_closed (); + transport = + svc_handler->transport (); - // In case of failures and close() has not be called. - if (result == -1 && - !closed) + if (result == -1) + { + // No immediate result, wait for completion + if (errno == EWOULDBLOCK) { - // First, cancel from connector. - this->base_connector_.cancel (svc_handler); - - // Double check to make sure the handler has not been closed - // yet. This double check is required to ensure that the - // connection handler was not closed yet by some other - // thread since it was still registered with the connector. - // Once connector.cancel() has been processed, we are - // assured that the connector will no longer open/close this - // handler. - closed = - svc_handler->is_closed (); - - // If closed, there is nothing to do here. If not closed, - // it was either opened or is still pending. - if (!closed) + // Try to wait until connection completion. Incase we block, then we + // get a connected transport or not. In case of non block we get + // a connected or not connected transport + if (!this->wait_for_connection_completion (resolver, + transport, + max_wait_time)) { - // Check if the handler has been opened. - int open = - svc_handler->is_open (); - - // Some other thread was able to open the handler even - // though wait failed for this thread. - if (open) - // Overwrite <result>. - result = 0; - else - { - // Assert that it is still connecting. - ACE_ASSERT (svc_handler->is_connecting ()); - - // Force close the handler now. - svc_handler->close (); - } + if (TAO_debug_level > 2) + ACE_ERROR ((LM_ERROR, "TAO (%P|%t) - SSLIOP_Connector::" + "ssliop_connect, " + "wait for completion failed\n")); } } + else + { + // Transport is not usable + transport = 0; + } } - // Irrespective of success or failure, remove the extra #REFCOUNT#. - svc_handler->remove_reference (); - - // In case of errors. - if (result == -1) + // In case of errors transport is zero + if (transport == 0) { // Give users a clue to the problem. if (TAO_debug_level) @@ -623,7 +594,7 @@ TAO::SSLIOP::Connector::ssliop_connect ( ssl_endpoint->addr_to_string (buffer, sizeof (buffer) - 1); ACE_DEBUG ((LM_ERROR, - ACE_TEXT ("TAO (%P|%t) %N:%l, SSL connection to ") + ACE_TEXT ("TAO (%P|%t) - SSL connection to ") ACE_TEXT ("<%s:%d> failed (%p)\n"), buffer, remote_address.get_port_number (), @@ -637,14 +608,11 @@ TAO::SSLIOP::Connector::ssliop_connect ( // #REFCOUNT# is one. if (TAO_debug_level > 2) ACE_DEBUG ((LM_DEBUG, - "TAO (%P|%t) - SSLIOP_Connector::ssliop_connect(): " + "TAO (%P|%t) - SSLIOP_Connector::ssliop_connect, " "new SSL connection to port %d on transport[%d]\n", remote_address.get_port_number (), svc_handler->peer ().get_handle ())); - transport = - svc_handler->transport (); - ssl_endpoint->qop (qop); ssl_endpoint->trust (trust); ssl_endpoint->credentials (credentials.in ()); @@ -664,34 +632,31 @@ TAO::SSLIOP::Connector::ssliop_connect ( if (TAO_debug_level > 0) { ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - IIOP_Connector::make_connection, " + "TAO (%P|%t) - SLIIOP_Connector::ssliop_connect, " "could not add the new connection to cache\n")); } return 0; } - // If the wait strategy wants us to be registered with the reactor - // then we do so. If registeration is required and it succeeds, - // #REFCOUNT# becomes two. - retval = transport->wait_strategy ()->register_handler (); - - // Registration failures. - if (retval != 0) + if (transport->is_connected () && + transport->wait_strategy ()->register_handler () != 0) { - // Purge from the connection cache. - transport->purge_entry (); + // Registration failures. + + // Purge from the connection cache, if we are not in the cache, this + // just does nothing. + (void) transport->purge_entry (); // Close the handler. - svc_handler->close (); + (void) transport->close_connection (); if (TAO_debug_level > 0) - { - ACE_ERROR ((LM_ERROR, - "TAO (%P|%t) - IIOP_Connector::make_connection, " - "could not register the new connection in the " - "reactor\n")); - } + ACE_ERROR ((LM_ERROR, + "TAO (%P|%t) - SSLIOP_Connector [%d]::ssliop_connect, " + "could not register the transport " + "in the reactor.\n", + transport->id ())); return 0; } @@ -771,3 +736,23 @@ TAO::SSLIOP::Connector::retrieve_credentials (TAO_Stub *stub, return ssliop_credentials._retn (); } + +int +TAO::SSLIOP::Connector::cancel_svc_handler ( + TAO_Connection_Handler * svc_handler) +{ + TAO::SSLIOP::Connection_Handler* handler= + dynamic_cast<TAO::SSLIOP::Connection_Handler*>(svc_handler); + + if (handler) + { + // Cancel from the connector + this->base_connector_.cancel (handler); + + return 0; + } + else + { + return -1; + } +} diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.h b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.h index 85e4362153c..9a3a5ddb1a2 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.h +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connector.h @@ -81,6 +81,9 @@ namespace TAO */ virtual TAO_Profile * make_profile (ACE_ENV_SINGLE_ARG_DECL); + /// Cancel the passed cvs handler from the connector + virtual int cancel_svc_handler (TAO_Connection_Handler * svc_handler); + /// IIOP-specific connection establishment. /** * @note The IIOP endpoint is extracted from the SSLIOP endpoint. |