00001 #include "tao/Transport_Connector.h"
00002 #include "tao/Transport.h"
00003 #include "tao/ORB_Core.h"
00004 #include "tao/MProfile.h"
00005 #include "tao/Profile.h"
00006 #include "tao/Thread_Lane_Resources.h"
00007 #include "tao/debug.h"
00008 #include "tao/Connect_Strategy.h"
00009 #include "tao/LF_Multi_Event.h"
00010 #include "tao/Client_Strategy_Factory.h"
00011 #include "tao/Connection_Handler.h"
00012 #include "tao/Profile_Transport_Resolver.h"
00013 #include "tao/Wait_Strategy.h"
00014 #include "tao/SystemException.h"
00015 #include "tao/Endpoint.h"
00016 #include "tao/Base_Transport_Property.h"
00017
00018 #include "ace/OS_NS_string.h"
00019
00020
00021
00022 #if !defined (__ACE_INLINE__)
00023 # include "tao/Transport_Connector.inl"
00024 #endif
00025
00026 ACE_RCSID (tao,
00027 Connector,
00028 "$Id: Transport_Connector.cpp 85406 2009-05-20 09:07:56Z johnnyw $")
00029
00030 namespace
00031 {
00032 class TransportCleanupGuard
00033 {
00034 public:
00035
00036
00037 TransportCleanupGuard (TAO_Transport *tp)
00038 : tp_ (tp),
00039 awake_ (true)
00040 {
00041 }
00042
00043 ~TransportCleanupGuard ()
00044 {
00045 if (this->awake_ && this->tp_)
00046 {
00047
00048
00049 this->tp_->purge_entry ();
00050
00051
00052 this->tp_->close_connection ();
00053 this->tp_->remove_reference ();
00054 }
00055 }
00056
00057
00058 void clear ()
00059 {
00060 this->awake_ = false;
00061 }
00062
00063 private:
00064 TAO_Transport * const tp_;
00065 bool awake_;
00066 };
00067 }
00068
00069 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00070
00071
00072 TAO_Connector::TAO_Connector (CORBA::ULong tag)
00073 : active_connect_strategy_ (0),
00074 tag_ (tag),
00075 orb_core_ (0)
00076 {
00077 }
00078
00079 TAO_Connector::~TAO_Connector (void)
00080 {
00081 delete this->active_connect_strategy_;
00082 }
00083
00084 TAO_Profile *
00085 TAO_Connector::corbaloc_scan (const char *str, size_t &len)
00086 {
00087 if (this->check_prefix (str) != 0)
00088 return 0;
00089 const char *comma_pos = ACE_OS::strchr (str,',');
00090 const char *slash_pos = ACE_OS::strchr (str,'/');
00091 if (comma_pos == 0 && slash_pos == 0)
00092 {
00093 len = ACE_OS::strlen (str);
00094 }
00095 else if (comma_pos == 0 || comma_pos > slash_pos)
00096 len = (slash_pos - str);
00097 else len = comma_pos - str;
00098 return this->make_profile();
00099 }
00100
00101 int
00102 TAO_Connector::make_mprofile (const char *string, TAO_MProfile &mprofile)
00103 {
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 if (!string || !*string)
00114 {
00115 throw ::CORBA::INV_OBJREF (
00116 CORBA::SystemException::_tao_minor_code (
00117 0,
00118 EINVAL),
00119 CORBA::COMPLETED_NO);
00120 }
00121
00122
00123
00124 if (this->check_prefix (string) != 0)
00125 {
00126 return 1;
00127
00128
00129
00130
00131 }
00132
00133 if (TAO_debug_level > 0)
00134 {
00135 ACE_DEBUG ((LM_DEBUG,
00136 ACE_TEXT ("TAO (%P|%t) - TAO_Connector::make_mprofile ")
00137 ACE_TEXT ("<%C>\n"),
00138 string));
00139 }
00140
00141 ACE_CString ior;
00142
00143 ior.set (string, ACE_OS::strlen (string), 1);
00144
00145
00146 ACE_CString::size_type ior_index = ior.find ("://");
00147
00148 if (ior_index == ACE_CString::npos)
00149 {
00150 throw ::CORBA::INV_OBJREF ();
00151
00152 }
00153 else
00154 {
00155 ior_index += 3;
00156
00157
00158 }
00159
00160
00161 const ACE_CString::size_type objkey_index =
00162 ior.find (this->object_key_delimiter (), ior_index);
00163
00164 if (objkey_index == 0 || objkey_index == ACE_CString::npos)
00165 {
00166 throw ::CORBA::INV_OBJREF ();
00167
00168 }
00169
00170 const char endpoint_delimiter = ',';
00171
00172
00173
00174
00175
00176 CORBA::ULong profile_count = 1;
00177
00178
00179
00180
00181 for (ACE_CString::size_type i = ior_index; i < objkey_index; ++i)
00182 {
00183 if (ior[i] == endpoint_delimiter)
00184 ++profile_count;
00185 }
00186
00187
00188
00189 if (mprofile.set (profile_count) != static_cast<int> (profile_count))
00190 {
00191 throw ::CORBA::INV_OBJREF (
00192 CORBA::SystemException::_tao_minor_code (
00193 TAO_MPROFILE_CREATION_ERROR,
00194 0),
00195 CORBA::COMPLETED_NO);
00196
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 ACE_CString::size_type begin = 0;
00209 ACE_CString::size_type end = ior_index - 1;
00210
00211
00212 for (CORBA::ULong j = 0; j < profile_count; ++j)
00213 {
00214 begin = end + 1;
00215
00216 if (j < profile_count - 1)
00217 {
00218 end = ior.find (endpoint_delimiter, begin);
00219 }
00220 else
00221 {
00222 end = objkey_index;
00223 }
00224
00225 if (end < ior.length () && end != ior.npos)
00226 {
00227 ACE_CString endpoint = ior.substring (begin, end - begin);
00228
00229
00230 endpoint += ior.substring (objkey_index);
00231
00232
00233
00234
00235
00236
00237 TAO_Profile *profile =
00238 this->make_profile ();
00239
00240
00241
00242
00243
00244 profile->parse_string (endpoint.c_str ()
00245 );
00246
00247
00248 if (mprofile.give_profile (profile) == -1)
00249 {
00250 profile->_decr_refcnt ();
00251
00252 throw ::CORBA::INV_OBJREF (
00253 CORBA::SystemException::_tao_minor_code (
00254 TAO_MPROFILE_CREATION_ERROR,
00255 0),
00256 CORBA::COMPLETED_NO);
00257
00258
00259 }
00260 }
00261 else
00262 {
00263 throw ::CORBA::INV_OBJREF ();
00264
00265 }
00266 }
00267
00268 return 0;
00269 }
00270
00271 int
00272 TAO_Connector::supports_parallel_connects(void) const
00273 {
00274 return 0;
00275 }
00276
00277 TAO_Transport*
00278 TAO_Connector::make_parallel_connection (TAO::Profile_Transport_Resolver *,
00279 TAO_Transport_Descriptor_Interface &,
00280 ACE_Time_Value *)
00281 {
00282 return 0;
00283 }
00284
00285
00286 TAO_Transport*
00287 TAO_Connector::parallel_connect (TAO::Profile_Transport_Resolver *r,
00288 TAO_Transport_Descriptor_Interface *desc,
00289 ACE_Time_Value *timeout)
00290 {
00291 if (this->supports_parallel_connects() == 0)
00292 {
00293 errno = ENOTSUP;
00294 return 0;
00295 }
00296
00297 errno = 0;
00298 if (desc == 0)
00299 return 0;
00300 TAO_Endpoint *root_ep = desc->endpoint();
00301 TAO_Transport *base_transport = 0;
00302
00303 TAO::Transport_Cache_Manager &tcm =
00304 this->orb_core ()->lane_resources ().transport_cache ();
00305
00306
00307
00308
00309 for (TAO_Endpoint *ep = root_ep->next_filtered (this->orb_core(),0);
00310 ep != 0;
00311 ep = ep->next_filtered(this->orb_core(),root_ep))
00312 {
00313 TAO_Base_Transport_Property desc2(ep,0);
00314 size_t busy_count = 0;
00315 if (tcm.find_transport (&desc2, base_transport, busy_count) ==
00316 TAO::Transport_Cache_Manager::CACHE_FOUND_AVAILABLE )
00317 {
00318 if (TAO_debug_level)
00319 {
00320 ACE_DEBUG ((LM_DEBUG,
00321 ACE_TEXT ("TAO (%P|%t) - TAO_Connector::parallel_connect: ")
00322 ACE_TEXT ("found a transport [%d]\n"),
00323 base_transport->id ()));
00324 }
00325 return base_transport;
00326 }
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 unsigned int endpoint_count = 0;
00338 for (TAO_Endpoint *ep = root_ep->next_filtered (this->orb_core(),0);
00339 ep != 0;
00340 ep = ep->next_filtered(this->orb_core(),root_ep))
00341 if (this->set_validate_endpoint (ep) == 0)
00342 ++endpoint_count;
00343 if (endpoint_count == 0)
00344 return 0;
00345 return this->make_parallel_connection (r,*desc,timeout);
00346 }
00347
00348 bool
00349 TAO_Connector::wait_for_transport (TAO::Profile_Transport_Resolver *r,
00350 TAO_Transport *transport,
00351 ACE_Time_Value *timeout,
00352 bool force_wait)
00353 {
00354 if (transport->connection_handler ()->is_timeout ())
00355 {
00356 if (TAO_debug_level > 2)
00357 {
00358 ACE_DEBUG ((LM_DEBUG,
00359 ACE_TEXT ("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00360 ACE_TEXT ("transport [%d], Connection Timed out.\n"),
00361 transport->id ()));
00362 }
00363 transport->purge_entry ();
00364 return false;
00365 }
00366 else if (transport->connection_handler ()->is_closed ())
00367 {
00368 if (TAO_debug_level > 2)
00369 {
00370 ACE_DEBUG ((LM_DEBUG,
00371 ACE_TEXT ("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00372 ACE_TEXT ("transport [%d], Connection failed. (%d)\n"),
00373 transport->id (), ACE_ERRNO_GET));
00374 }
00375
00376
00377
00378 transport->purge_entry ();
00379
00380
00381 transport->close_connection ();
00382
00383 return false;
00384 }
00385 else if (transport->connection_handler ()->is_open ())
00386 {
00387 if (TAO_debug_level > 5)
00388 {
00389 ACE_DEBUG ((LM_DEBUG,
00390 ACE_TEXT("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00391 ACE_TEXT("transport [%d], connection is open: no wait.\n"),
00392 transport->id () ));
00393 }
00394
00395 return true;
00396 }
00397 else if (force_wait || r->blocked_connect ())
00398 {
00399 if (TAO_debug_level > 2)
00400 {
00401 ACE_DEBUG ((LM_DEBUG,
00402 ACE_TEXT("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00403 ACE_TEXT("waiting on transport [%d]\n"),
00404 transport->id () ));
00405 }
00406
00407
00408
00409
00410
00411
00412 int result = 0;
00413 if (timeout == 0 && !r->blocked_connect ())
00414 {
00415 ACE_Time_Value tv (0, 500);
00416 result = this->active_connect_strategy_->wait (transport, &tv);
00417 }
00418 else
00419 result = this->active_connect_strategy_->wait (transport, timeout);
00420
00421 if (result == -1 && errno == ETIME)
00422 {
00423 if (TAO_debug_level > 2)
00424 {
00425 ACE_DEBUG ((LM_DEBUG,
00426 ACE_TEXT("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00427 ACE_TEXT(" timeout while waiting on transport [%d]\n"),
00428 transport->id () ));
00429 }
00430 }
00431 else if (result == -1)
00432 {
00433 if (TAO_debug_level > 2)
00434 {
00435 static int complain10times = 10;
00436 if (complain10times > 0)
00437 {
00438 --complain10times;
00439 ACE_DEBUG ((LM_DEBUG,
00440 ACE_TEXT("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00441 ACE_TEXT(" unknown error waiting on transport [%d] (%d)\n"),
00442 transport->id (),
00443 ACE_ERRNO_GET));
00444 }
00445 }
00446
00447
00448 transport->purge_entry ();
00449
00450
00451 transport->close_connection ();
00452 }
00453 else
00454 {
00455 if (TAO_debug_level > 5)
00456 {
00457 ACE_DEBUG ((LM_DEBUG,
00458 ACE_TEXT("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00459 ACE_TEXT("transport [%d], wait completed ok.\n"),
00460 transport->id () ));
00461 }
00462 return true;
00463 }
00464 }
00465 else
00466 {
00467 if (TAO_debug_level > 2)
00468 {
00469 ACE_DEBUG ((LM_DEBUG,
00470 ACE_TEXT ("TAO (%P|%t) - TAO_Connector::wait_for_transport, ")
00471 ACE_TEXT ("Connection not complete [%d] reset state to ")
00472 ACE_TEXT ("LFS_CONNECTION_WAIT\n"), transport->id ()));
00473 }
00474 transport->connection_handler ()->reset_state (
00475 TAO_LF_Event::LFS_CONNECTION_WAIT);
00476
00477 return true;
00478 }
00479
00480 return false;
00481 }
00482
00483 TAO_Transport*
00484 TAO_Connector::connect (TAO::Profile_Transport_Resolver *r,
00485 TAO_Transport_Descriptor_Interface *desc,
00486 ACE_Time_Value *timeout)
00487 {
00488 TAO::Transport_Cache_Manager &tcm =
00489 this->orb_core ()->lane_resources ().transport_cache ();
00490
00491
00492
00493 while (true)
00494 {
00495
00496
00497 TAO_Transport *base_transport = 0;
00498 size_t busy_count = 0;
00499 TAO::Transport_Cache_Manager::Find_Result found =
00500 tcm.find_transport (desc,
00501 base_transport,
00502 busy_count);
00503
00504 if (found == TAO::Transport_Cache_Manager::CACHE_FOUND_AVAILABLE)
00505 {
00506 TAO_Connection_Handler *ch = base_transport->connection_handler ();
00507
00508 if (ch->error_detected ())
00509 {
00510 if (TAO_debug_level > 0)
00511 {
00512 ACE_DEBUG ((LM_DEBUG,
00513 ACE_TEXT("TAO (%P|%t) Transport_Connector::connect, ")
00514 ACE_TEXT("error in transport from cache\n")));
00515 }
00516 (void) base_transport->close_connection ();
00517 (void) base_transport->purge_entry ();
00518 base_transport->remove_reference ();
00519 }
00520 else if (ch->is_closed ())
00521 {
00522 if (TAO_debug_level > 0)
00523 {
00524 ACE_DEBUG ((LM_DEBUG,
00525 ACE_TEXT("TAO (%P|%t) Transport_Connector::connect, ")
00526 ACE_TEXT("closed transport from cache\n")));
00527 }
00528 (void) base_transport->purge_entry ();
00529 base_transport->remove_reference ();
00530 }
00531 else
00532 {
00533 if (TAO_debug_level > 4)
00534 {
00535 TAO::Connection_Role cr = base_transport->opened_as ();
00536
00537 ACE_DEBUG ((LM_DEBUG,
00538 ACE_TEXT("TAO (%P|%t) - Transport_Connector::connect, ")
00539 ACE_TEXT("got an existing %C Transport[%d] in role %C\n"),
00540 base_transport->is_connected () ? "connected" :
00541 "unconnected",
00542 base_transport->id (),
00543 cr == TAO::TAO_SERVER_ROLE ? "TAO_SERVER_ROLE" :
00544 cr == TAO::TAO_CLIENT_ROLE ? "TAO_CLIENT_ROLE" :
00545 "TAO_UNSPECIFIED_ROLE" ));
00546 }
00547
00548
00549 if (base_transport->is_connected ())
00550 return base_transport;
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566 TransportCleanupGuard tg(base_transport);
00567 if (!this->wait_for_connection_completion (r, *desc,
00568 base_transport,
00569 timeout))
00570 {
00571 if (TAO_debug_level > 2)
00572 {
00573 ACE_ERROR ((LM_ERROR,
00574 "TAO (%P|%t) - Transport_Connector::connect,"
00575 " wait for completion failed\n"));
00576 }
00577 return 0;
00578 }
00579
00580 if (base_transport->is_connected () &&
00581 base_transport->wait_strategy ()->register_handler () == -1)
00582 {
00583
00584 if (TAO_debug_level > 0)
00585 {
00586 ACE_ERROR ((LM_ERROR,
00587 "TAO (%P|%t) - Transport_Connector::connect, "
00588 "could not register the transport [%d]"
00589 "in the reactor.\n",
00590 base_transport->id ()));
00591 }
00592 return 0;
00593 }
00594
00595 tg.clear ();
00596 return base_transport;
00597 }
00598 }
00599 else if (found == TAO::Transport_Cache_Manager::CACHE_FOUND_CONNECTING)
00600 {
00601 if (r->blocked_connect ())
00602 {
00603 if (TAO_debug_level > 4)
00604 {
00605 ACE_DEBUG ((LM_DEBUG,
00606 ACE_TEXT("TAO (%P|%t) - ")
00607 ACE_TEXT("Transport_Connector::waiting ")
00608 ACE_TEXT("for connection on transport [%d]\n"),
00609 base_transport->id ()));
00610 }
00611
00612
00613
00614 if (this->wait_for_transport (r, base_transport, timeout, false))
00615 {
00616
00617
00618 if (!base_transport->register_if_necessary ())
00619 {
00620 base_transport->remove_reference ();
00621 return 0;
00622 }
00623 }
00624
00625
00626
00627
00628 base_transport->remove_reference ();
00629 }
00630 else
00631 {
00632 if (TAO_debug_level > 4)
00633 {
00634 ACE_DEBUG ((LM_DEBUG,
00635 ACE_TEXT("TAO (%P|%t) - ")
00636 ACE_TEXT("Transport_Connector::non-blocking:")
00637 ACE_TEXT("returning unconnected ")
00638 ACE_TEXT("transport [%d]\n"),
00639 base_transport->id ()));
00640 }
00641
00642
00643 return base_transport;
00644 }
00645 }
00646 else
00647 {
00648 if (desc == 0 ||
00649 (this->set_validate_endpoint (desc->endpoint ()) == -1))
00650 return 0;
00651
00652
00653
00654 tcm.purge ();
00655 bool make_new_connection =
00656 (found == TAO::Transport_Cache_Manager::CACHE_FOUND_NONE) ||
00657 (found == TAO::Transport_Cache_Manager::CACHE_FOUND_BUSY
00658 && this->new_connection_is_ok (busy_count));
00659
00660 if (make_new_connection)
00661 {
00662
00663
00664 if (base_transport != 0)
00665 {
00666 base_transport->remove_reference ();
00667 }
00668
00669 base_transport = this->make_connection (r, *desc, timeout);
00670 if (base_transport == 0)
00671 {
00672 if (TAO_debug_level > 4)
00673 {
00674 ACE_DEBUG ((LM_DEBUG,
00675 ACE_TEXT ("TAO (%P|%t) - Transport_Connector::")
00676 ACE_TEXT ("connect, make_connection failed\n")));
00677 }
00678 return 0;
00679 }
00680
00681 if (TAO_debug_level > 4)
00682 {
00683 ACE_DEBUG ((LM_DEBUG,
00684 ACE_TEXT("TAO (%P|%t) - ")
00685 ACE_TEXT("Transport_Connector::connect, ")
00686 ACE_TEXT("opening Transport[%d] in ")
00687 ACE_TEXT("TAO_CLIENT_ROLE\n"),
00688 base_transport->id ()));
00689 }
00690
00691
00692
00693 if (!base_transport->post_connect_hook ())
00694 {
00695 if (TAO_debug_level > 4)
00696 {
00697 ACE_DEBUG ((LM_DEBUG,
00698 ACE_TEXT("TAO (%P|%t) - Post_connect_hook ")
00699 ACE_TEXT("failed. ")
00700 ACE_TEXT("Purging transport[%d]\n"),
00701 base_transport->id ()));
00702 }
00703 (void) base_transport->purge_entry ();
00704 }
00705
00706
00707
00708
00709
00710 base_transport->remove_reference ();
00711 }
00712 else
00713 {
00714 (void) this->wait_for_transport (r, base_transport,
00715 timeout, true);
00716 base_transport->remove_reference ();
00717 }
00718 }
00719 }
00720 }
00721
00722 bool
00723 TAO_Connector::wait_for_connection_completion (
00724 TAO::Profile_Transport_Resolver *r,
00725 TAO_Transport_Descriptor_Interface &desc,
00726 TAO_Transport *&transport,
00727 ACE_Time_Value *timeout)
00728 {
00729 int result = -1;
00730 if (transport->connection_handler ()->is_open ())
00731 {
00732 TAO::Transport_Cache_Manager &tcm =
00733 this->orb_core ()->lane_resources ().transport_cache ();
00734 result = tcm.cache_transport (&desc, transport);
00735 if (result == -1)
00736 {
00737
00738 }
00739 }
00740 else if (transport->connection_handler ()->is_timeout ())
00741 {
00742 if (TAO_debug_level > 2)
00743 {
00744 ACE_DEBUG ((LM_DEBUG,
00745 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00746 ACE_TEXT("wait_for_connection_completion, ")
00747 ACE_TEXT("transport [%d], Connection timed out.\n"),
00748 transport->id ()));
00749 }
00750 result = -1;
00751 errno = ETIME;
00752 }
00753 else if (transport->connection_handler ()->is_closed ())
00754 {
00755 if (TAO_debug_level > 2)
00756 {
00757 ACE_DEBUG ((LM_DEBUG,
00758 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00759 ACE_TEXT("wait_for_connection_completion, ")
00760 ACE_TEXT("transport [%d], Connection failed. (%d) %p\n"),
00761 transport->id (), ACE_ERRNO_GET, ACE_TEXT("")));
00762 }
00763 result = -1;
00764 }
00765 else
00766 {
00767 if (TAO_debug_level > 2)
00768 {
00769 ACE_DEBUG ((LM_DEBUG,
00770 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00771 ACE_TEXT("wait_for_connection_completion, ")
00772 ACE_TEXT("transport [%d], Connection not complete.\n"),
00773 transport->id ()));
00774 }
00775
00776 TAO::Transport_Cache_Manager &tcm =
00777 this->orb_core ()->lane_resources ().transport_cache ();
00778 result = tcm.cache_transport (&desc, transport, TAO::ENTRY_CONNECTING);
00779
00780 if (result != -1)
00781 {
00782 if (r->blocked_connect ())
00783 {
00784 if (TAO_debug_level > 2)
00785 {
00786 ACE_DEBUG ((LM_DEBUG,
00787 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00788 ACE_TEXT("wait_for_connection_completion, ")
00789 ACE_TEXT("going to wait for connection completion on ")
00790 ACE_TEXT("transport[%d]\n"),
00791 transport->id ()));
00792 }
00793
00794 result = this->active_connect_strategy_->wait (transport, timeout);
00795
00796 if (TAO_debug_level > 2)
00797 {
00798 ACE_DEBUG ((LM_DEBUG,
00799 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00800 ACE_TEXT("wait_for_connection_completion, ")
00801 ACE_TEXT("transport [%d], wait done result = %d\n"),
00802 transport->id (), result));
00803 }
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 if (result == -1)
00814 {
00815 if (errno == ETIME)
00816 {
00817 if (timeout == 0)
00818 {
00819
00820
00821
00822
00823 transport->purge_entry ();
00824 }
00825
00826 if (TAO_debug_level > 2)
00827 {
00828 ACE_DEBUG ((LM_DEBUG,
00829 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00830 ACE_TEXT("wait_for_connection_completion, ")
00831 ACE_TEXT("transport [%d], Connection timed out.\n"),
00832 transport->id ()));
00833 }
00834 }
00835 else
00836 {
00837
00838
00839 if (TAO_debug_level > 2)
00840 {
00841 ACE_ERROR ((LM_ERROR,
00842 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00843 ACE_TEXT("wait_for_connection_completion, ")
00844 ACE_TEXT("transport [%d], wait for completion failed")
00845 ACE_TEXT(" (%d) %p\n"),
00846 transport->id (), ACE_ERRNO_GET, ACE_TEXT("")));
00847 }
00848 TAO_Connection_Handler *con =
00849 transport->connection_handler ();
00850 result = this->check_connection_closure (con);
00851 transport->purge_entry ();
00852 }
00853 }
00854 }
00855 else
00856 {
00857 transport->connection_handler ()->
00858 reset_state (TAO_LF_Event::LFS_CONNECTION_WAIT);
00859 if (TAO_debug_level > 9)
00860 {
00861 ACE_DEBUG ((LM_DEBUG,
00862 ACE_TEXT("TAO (%P|%t) - TAO_Connector[%d]::")
00863 ACE_TEXT("wait_for_connection_completion reset_state to ")
00864 ACE_TEXT("LFS_CONNECTION_WAIT\n"), transport->id ()));
00865 }
00866 result = 0;
00867 }
00868 }
00869 }
00870
00871 if (result == -1)
00872 {
00873
00874
00875
00876 transport = 0;
00877 return false;
00878 }
00879
00880
00881
00882 return true;
00883 }
00884
00885 bool
00886 TAO_Connector::wait_for_connection_completion (
00887 TAO::Profile_Transport_Resolver *r,
00888 TAO_Transport *&the_winner,
00889 TAO_Transport **transport,
00890 unsigned int count,
00891 TAO_LF_Multi_Event *mev,
00892 ACE_Time_Value *timeout)
00893 {
00894 if (TAO_debug_level > 2)
00895 {
00896 ACE_DEBUG ((LM_DEBUG,
00897 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00898 ACE_TEXT("wait_for_connection_completion, ")
00899 ACE_TEXT("waiting for connection completion on ")
00900 ACE_TEXT("%d transports, ["),
00901 count));
00902 for (unsigned int i = 0; i < count; i++)
00903 ACE_DEBUG ((LM_DEBUG,
00904 ACE_TEXT("%d%C"),transport[i]->id (),
00905 (i < (count -1) ? ", " : "]\n")));
00906 }
00907
00908 int result = -1;
00909 if (r->blocked_connect ())
00910 {
00911 result = this->active_connect_strategy_->wait (mev, timeout);
00912 the_winner = 0;
00913 }
00914 else
00915 {
00916 errno = ETIME;
00917 }
00918
00919 if (result != -1)
00920 {
00921 the_winner = mev->winner()->transport();
00922 if (TAO_debug_level > 2)
00923 {
00924 ACE_DEBUG ((LM_DEBUG,
00925 ACE_TEXT ("TAO (%P|%t) - Transport_Connector::")
00926 ACE_TEXT ("wait_for_connection_completion, ")
00927 ACE_TEXT ("transport [%d]\n"),
00928 the_winner->id ()));
00929 }
00930 }
00931 else if (errno == ETIME)
00932 {
00933
00934
00935
00936
00937
00938 for (unsigned int i = 0; i < count; i++)
00939 if (!transport[i]->connection_handler()->is_closed())
00940 {
00941 the_winner = transport[i];
00942 break;
00943 }
00944 }
00945
00946
00947
00948
00949 for (unsigned int i = 0; i < count; i++)
00950 {
00951 if (transport[i] != the_winner)
00952 this->check_connection_closure (transport[i]->connection_handler());
00953
00954
00955 }
00956
00957
00958 if (the_winner == 0)
00959 {
00960
00961
00962 if (TAO_debug_level > 2)
00963 {
00964 ACE_ERROR ((LM_ERROR,
00965 ACE_TEXT ("TAO (%P|%t) - Transport_Connector::")
00966 ACE_TEXT ("wait_for_connection_completion, failed\n")
00967 ));
00968 }
00969
00970 return false;
00971 }
00972
00973
00974
00975
00976 if (r->blocked_connect () && !the_winner->is_connected ())
00977 {
00978 if (TAO_debug_level > 2)
00979 {
00980 ACE_DEBUG ((LM_DEBUG,
00981 ACE_TEXT("TAO (%P|%t) - Transport_Connector::")
00982 ACE_TEXT("wait_for_connection_completion, ")
00983 ACE_TEXT("no connected transport for a blocked connection, ")
00984 ACE_TEXT("cancelling connections and reverting things\n")));
00985 }
00986
00987
00988
00989 (void) this->cancel_svc_handler (the_winner->connection_handler ());
00990 the_winner = 0;
00991 return false;
00992 }
00993
00994
00995
00996
00997 return true;
00998 }
00999
01000 int
01001 TAO_Connector::create_connect_strategy (void)
01002 {
01003 if (this->active_connect_strategy_ == 0)
01004 {
01005 this->active_connect_strategy_ =
01006 this->orb_core_->client_factory ()->create_connect_strategy (
01007 this->orb_core_);
01008 }
01009
01010 if (this->active_connect_strategy_ == 0)
01011 {
01012 return -1;
01013 }
01014
01015 return 0;
01016 }
01017
01018 bool
01019 TAO_Connector::new_connection_is_ok (size_t busy_count)
01020 {
01021 if (this->orb_core_ == 0)
01022 return true;
01023
01024 unsigned int mux_limit = this->orb_core_->resource_factory ()
01025 ->max_muxed_connections ();
01026
01027 return mux_limit == 0 || busy_count < mux_limit;
01028 }
01029
01030 int
01031 TAO_Connector::check_connection_closure (
01032 TAO_Connection_Handler *connection_handler)
01033 {
01034 int result = -1;
01035
01036
01037 bool closed = connection_handler->is_closed ();
01038
01039
01040 if (!closed)
01041 {
01042
01043 if (this->cancel_svc_handler (connection_handler) == -1)
01044 return -1;
01045
01046
01047
01048
01049
01050
01051
01052
01053 closed = connection_handler->is_closed ();
01054
01055
01056
01057 if (!closed)
01058 {
01059
01060 const bool open = connection_handler->is_open ();
01061
01062
01063
01064 if (open)
01065 {
01066
01067 result = 0;
01068 }
01069 else
01070 {
01071
01072 ACE_ASSERT (connection_handler->is_connecting ());
01073
01074
01075 connection_handler->close_handler ();
01076 }
01077 }
01078 }
01079
01080 return result;
01081 }
01082
01083
01084
01085 TAO_END_VERSIONED_NAMESPACE_DECL