int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies (1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); if (parse_args (argc, argv) != 0) return 1; // Get the sender reference.. CORBA::Object_var tmp = orb->string_to_object(ior); Test::Sender_var sender = Test::Sender::_narrow(tmp.in ()); if (CORBA::is_nil (sender.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil coordinator reference <%s>\n", ior), 1); } Client_Task client_task (orb.in(), sender.in (), ACE_Thread_Manager::instance (), number_of_oneways); Server_Task server_task (orb.in (), ACE_Thread_Manager::instance ()); // Before creating threads we will let the sender know that we // will have two threads that would make invocations.. // this is the first oneway we do, so after this we would have a queue // on one of the transports sender->active_objects ((CORBA::Short) number_of_client_tasks); TAO::Transport_Cache_Manager& manager = orb->orb_core()->lane_resources ().transport_cache (); TAO::Transport_Cache_Manager::HASH_MAP& cachemap = manager.map(); TAO::Transport_Cache_Manager::HASH_MAP_ITER end_iter = cachemap.end (); bool tranportwithqueue = false; for (TAO::Transport_Cache_Manager::HASH_MAP_ITER iter = cachemap.begin (); iter != end_iter; ++iter) { TAO_Transport* transport = (*iter).int_id_.transport (); if (transport->queue_is_empty() == 0 && transport->is_connected() == false) { tranportwithqueue = true; break; } } if (!tranportwithqueue) { ACE_ERROR ((LM_ERROR, "(%P|%t) Error: expect a not connected transport with a queue\n")); } else { ACE_DEBUG((LM_DEBUG, "(%P|%t) Found not connected transport with a queue\n")); } if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 2,1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating server task\n")); } if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, number_of_client_tasks, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating client task\n")); } ACE_Thread_Manager::instance ()->wait (); ACE_DEBUG ((LM_DEBUG, "Event Loop finished\n")); orb->destroy (); if (tranportwithqueue == false) { return 1; } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
TAO_Transport * TAO::IIOP_SSL_Connector::make_connection ( TAO::Profile_Transport_Resolver *r, TAO_Transport_Descriptor_Interface &desc, ACE_Time_Value *max_wait_time) { TAO_IIOP_Endpoint *iiop_endpoint = dynamic_cast<TAO_IIOP_Endpoint *> (desc.endpoint ()); if (iiop_endpoint == 0) return 0; const ACE_INET_Addr &remote_address = iiop_endpoint->object_addr (); if (TAO_debug_level > 4) ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) IIOP_SSL_Connector::connect ") ACE_TEXT ("making a new connection\n"))); // Get the right synch options ACE_Synch_Options synch_options; 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_connect ()) { synch_options.timeout (ACE_Time_Value::zero); max_wait_time = &tmp_zero; } IIOP_SSL_Connection_Handler *svc_handler = 0; // Connect. int result = this->base_connector_.connect (svc_handler, remote_address, synch_options); // Make sure that we always do a remove_reference ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler); TAO_Transport *transport = svc_handler->transport (); if (result == -1) { // No immediate result, wait for completion if (errno == EWOULDBLOCK) { // 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, desc, transport, max_wait_time)) { if (TAO_debug_level > 2) ORBSVCS_ERROR ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::" "make_connection, " "wait for completion failed\n")); } } else { // Transport is not usable transport = 0; } } // In case of errors transport is zero if (transport == 0) { // Give users a clue to the problem. if (TAO_debug_level) { ORBSVCS_DEBUG ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, " "connection to <%s:%d> failed (%p)\n", iiop_endpoint->host (), iiop_endpoint->port (), "errno")); } return 0; } if (svc_handler->keep_waiting (this->orb_core ()->leader_follower ())) { svc_handler->connection_pending (); } // At this point, the connection has be successfully connected. // #REFCOUNT# is one. if (TAO_debug_level > 2) ORBSVCS_DEBUG ((LM_DEBUG, "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 ())); // Add the handler to Cache int retval = this->orb_core ()->lane_resources ().transport_cache ().cache_transport ( &desc, transport); // Failure in adding to cache. if (retval == -1) { // Close the handler. svc_handler->close (); if (TAO_debug_level > 0) { ORBSVCS_ERROR ((LM_ERROR, "TAO (%P|%t) - IIOP_SSL_Connector::make_connection, " "could not add the new connection to cache\n")); } return 0; } if (transport->is_connected () && transport->wait_strategy ()->register_handler () != 0) { // 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. (void) transport->close_connection (); if (TAO_debug_level > 0) ORBSVCS_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; } svc_handler_auto_ptr.release (); return transport; }
TAO_Transport * TAO_UIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *r, TAO_Transport_Descriptor_Interface &desc, ACE_Time_Value *max_wait_time) { if (TAO_debug_level > 0) TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - UIUP_Connector::make_connection, ") ACE_TEXT ("looking for UIOP connection.\n"))); TAO_UIOP_Endpoint *uiop_endpoint = this->remote_endpoint (desc.endpoint ()); if (uiop_endpoint == 0) return 0; const ACE_UNIX_Addr &remote_address = uiop_endpoint->object_addr (); if (TAO_debug_level > 2) TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - UIUP_Connector::make_connection, ") ACE_TEXT ("making a new connection\n"))); // Get the right synch options ACE_Synch_Options synch_options; this->active_connect_strategy_->synch_options (max_wait_time, synch_options); // The code used to set the timeout to zero, with the intent of // polling the reactor for connection completion. However, the side-effect // was to cause the connection to timeout immediately. TAO_UIOP_Connection_Handler *svc_handler = 0; // Connect. int result = this->base_connector_.connect (svc_handler, remote_address, synch_options); // Make sure that we always do a remove_reference ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler); TAO_Transport *transport = svc_handler->transport (); if (result == -1) { // No immediate result, wait for completion if (errno == EWOULDBLOCK) { // 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, desc, transport, max_wait_time)) { if (TAO_debug_level > 2) TAOLIB_ERROR ((LM_ERROR, "TAO (%P|%t) - UIOP_Connector::" "make_connection, " "wait for completion failed\n")); } } else { // Transport is not usable transport = 0; } } // In case of errors transport is zero if (transport == 0) { // Give users a clue to the problem. if (TAO_debug_level > 3) TAOLIB_ERROR ((LM_ERROR, "TAO (%P|%t) - UIOP_Connector::make_connection, " "connection to <%C> failed (%p)\n", uiop_endpoint->rendezvous_point (), ACE_TEXT("errno"))); return 0; } if (svc_handler->keep_waiting ()) { svc_handler->connection_pending (); } if (svc_handler->error_detected ()) { svc_handler->cancel_pending_connection (); } // At this point, the connection has be successfully created // connected or not connected, but we have a connection. if (TAO_debug_level > 2) TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - UIOP_Connector::make_connection, " "new %C connection to <%C> on Transport[%d]\n", transport->is_connected() ? "connected" : "not connected", uiop_endpoint->rendezvous_point (), svc_handler->peer ().get_handle ())); // Add the handler to Cache int retval = this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc, transport); // Failure in adding to cache. if (retval == -1) { // Close the handler. svc_handler->close (); if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, ACE_TEXT ("TAO (%P|%t) - UIOP_Connector::make_connection, ") ACE_TEXT ("could not add the new connection to Cache\n"))); } return 0; } if (svc_handler->error_detected ()) { svc_handler->cancel_pending_connection (); transport->purge_entry(); return 0; } if (transport->is_connected () && transport->wait_strategy ()->register_handler () != 0) { // 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. (void) transport->close_connection (); if (TAO_debug_level > 0) TAOLIB_ERROR ((LM_ERROR, "TAO (%P|%t) - UIOP_Connector [%d]::make_connection, " "could not register the transport " "in the reactor.\n", transport->id ())); return 0; } svc_handler_auto_ptr.release (); return transport; }
TAO_Transport * TAO_SHMIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *, TAO_Transport_Descriptor_Interface &desc, ACE_Time_Value *timeout) { if (TAO_debug_level > 0) TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - SHMIOP_Connector::make_connection, ") ACE_TEXT ("looking for SHMIOP connection.\n"))); TAO_SHMIOP_Endpoint *shmiop_endpoint = this->remote_endpoint (desc.endpoint ()); if (shmiop_endpoint == 0) return 0; const ACE_INET_Addr &remote_address = shmiop_endpoint->object_addr (); if (TAO_debug_level > 2) TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - SHMIOP_Connector::make_connection, " "making a new connection to <%C:%d>\n", shmiop_endpoint->host (), shmiop_endpoint->port ())); // Get the right synch options ACE_Synch_Options synch_options; this->active_connect_strategy_->synch_options (timeout, synch_options); TAO_SHMIOP_Connection_Handler *svc_handler = 0; // Connect. int result = this->base_connector_.connect (svc_handler, remote_address, synch_options); // Make sure that we always do a remove_reference ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler); // In case of errors. if (result == -1) { // Give users a clue to the problem. if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, ACE_TEXT ("TAO (%P|%t) - SHMIOP_Connector::make_connection, ") ACE_TEXT ("connection to <%C:%u> failed (%p)\n"), shmiop_endpoint->host (), shmiop_endpoint->port (), ACE_TEXT ("errno"))); } return 0; } if (svc_handler->keep_waiting ()) { svc_handler->connection_pending (); } if (svc_handler->error_detected ()) { svc_handler->cancel_pending_connection (); } TAO_Transport *transport = svc_handler->transport (); // At this point, the connection has be successfully connected. // #REFCOUNT# is one. if (TAO_debug_level > 2) TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - SHMIOP_Connector::make_connection, " "new %C connection to <%C:%d> on Transport[%d]\n", transport->is_connected() ? "connected" : "not connected", shmiop_endpoint->host (), shmiop_endpoint->port (), svc_handler->peer ().get_handle ())); // Add the handler to Cache int retval = this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc, transport); // Failure in adding to cache. if (retval == -1) { // Close the handler. svc_handler->close (); if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, ACE_TEXT("TAO (%P|%t) - SHMIOP_Connector::make_connection, ") ACE_TEXT("could not add the new connection to cache\n"))); } return 0; } if (svc_handler->error_detected ()) { svc_handler->cancel_pending_connection (); transport->purge_entry(); return 0; } if (transport->is_connected () && transport->wait_strategy ()->register_handler () != 0) { // 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. (void) transport->close_connection (); if (TAO_debug_level > 0) TAOLIB_ERROR ((LM_ERROR, "TAO (%P|%t) - SHMIOP_Connector [%d]::make_connection, " "could not register the transport in the reactor.\n", transport->id ())); return 0; } svc_handler_auto_ptr.release (); return transport; }