示例#1
0
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;
}
示例#2
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;
}
示例#3
0
TAO_Transport *
TAO_UIPMC_Connector::make_connection (TAO::Profile_Transport_Resolver *,
                                      TAO_Transport_Descriptor_Interface &desc,
                                      ACE_Time_Value *)
{
  TAO_UIPMC_Endpoint *uipmc_endpoint =
    dynamic_cast<TAO_UIPMC_Endpoint *> (desc.endpoint ());

  if (uipmc_endpoint == 0)
    return 0;

  const ACE_INET_Addr &remote_address =
    uipmc_endpoint->object_addr ();

#if defined (ACE_HAS_IPV6) && !defined (ACE_HAS_IPV6_V6ONLY)
  // Check if we need to invalidate accepted connections
  // from IPv4 mapped IPv6 addresses
  if (this->orb_core ()->orb_params ()->connect_ipv6_only () &&
      remote_address.is_ipv4_mapped_ipv6 ())
    {
      if (TAO_debug_level > 0)
        {
          ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16];

          (void) remote_address.addr_to_string (remote_as_string,
                                                sizeof remote_as_string);

          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) - UIPMC_Connector::open, ")
                      ACE_TEXT ("invalid connection to IPv4 mapped IPv6 ")
                      ACE_TEXT ("interface <%s>!\n"),
                      remote_as_string));
        }
      return 0;
    }
#endif /* ACE_HAS_IPV6 && ACE_HAS_IPV6_V6ONLY */

  TAO_UIPMC_Connection_Handler *svc_handler = 0;

  ACE_NEW_RETURN (svc_handler,
                  TAO_UIPMC_Connection_Handler (this->orb_core ()),
                  0);

  // Make sure that we always do a remove_reference
  ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler);

  u_short port = 0;
  const ACE_UINT32 ia_any = INADDR_ANY;
  ACE_INET_Addr any_addr(port, ia_any);

#if defined (ACE_HAS_IPV6)
  if (remote_address.get_type () == AF_INET6)
    any_addr.set (port,
                  ACE_IPV6_ANY);
#endif /* ACE_HAS_IPV6 */
  ACE_INET_Addr local_addr(any_addr);
  svc_handler->addr (remote_address);

  int retval= 0;
  while (uipmc_endpoint != 0)
    {
      if (uipmc_endpoint->is_preferred_network ())
        {
          local_addr.set(port, uipmc_endpoint->preferred_network ());
        }
      else
        {
           local_addr.set(any_addr);
        }
      svc_handler->local_addr (local_addr);
      retval = svc_handler->open (0);
      if (retval == 0)
        {
#if defined (ACE_HAS_IPV6)
          const char* prefer_if = uipmc_endpoint->preferred_if();
          if (prefer_if && ACE_OS::strlen(prefer_if))
            {
              if (svc_handler->peer ().set_nic(prefer_if, AF_INET6))
                {
                  if (TAO_debug_level > 0)
                        ORBSVCS_ERROR ((LM_ERROR,
                            "TAO (%P|%t) - UIPMC_Connector::make_connection, "
                            "connection to <%C:%u> - failed to set requested local network interface <%s>\n",
                             uipmc_endpoint->host (),
                             uipmc_endpoint->port (),
                             prefer_if));
                  retval = -1;
                }
            }
#endif /* ACE_HAS_IPV6 */
          break;
        }
      else
       {
           if (TAO_debug_level > 3)
                ORBSVCS_ERROR ((LM_ERROR,
                            "TAO (%P|%t) - UIPMC_Connector::make_connection, "
                            "connection to <%C:%u> from interface <%s> failed (%p)\n",
                             uipmc_endpoint->host (),
                             uipmc_endpoint->port (),
                             uipmc_endpoint->is_preferred_network () ? uipmc_endpoint->preferred_network () : "ANY",
                             ACE_TEXT ("errno")));
       }
      uipmc_endpoint = dynamic_cast<TAO_UIPMC_Endpoint *> (uipmc_endpoint->next());
    }

  // Failure to open a connection.
  if (retval != 0)
    {
      svc_handler->close ();

      if (TAO_debug_level > 0)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      "TAO (%P|%t) - UIPMC_Connector::make_connection, "
                      "failed to open the connection to <%C:%u>\n",
                      remote_address.get_host_addr (),
                      remote_address.get_port_number ()));
        }

      return 0;
    }

  // After the handler is opened we can try to obtain the real local address.
  svc_handler->peer ().get_local_addr (local_addr);
  svc_handler->local_addr (local_addr);

  if (TAO_debug_level > 2)
    {
      char local_hostaddr[INET6_ADDRSTRLEN];
      local_addr.get_host_addr (local_hostaddr, sizeof local_hostaddr);
      char remote_hostaddr[INET6_ADDRSTRLEN];
      remote_address.get_host_addr (remote_hostaddr, sizeof remote_hostaddr);

      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - UIPMC_Connector::make_connection, ")
                  ACE_TEXT ("new connection from <%C:%u> to <%C:%u> on ")
                  ACE_TEXT ("HANDLE %d\n"),
                  local_hostaddr,
                  local_addr.get_port_number (),
                  remote_hostaddr,
                  remote_address.get_port_number (),
                  svc_handler->get_handle ()));
    }

  TAO_Transport *transport = svc_handler->transport ();

  // In case of errors transport is zero
  if (transport == 0)
    {
      svc_handler->close ();

      // Give users a clue to the problem.
      if (TAO_debug_level)
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) - UIPMC_Connector:")
                      ACE_TEXT (":make_connection, connection to ")
                      ACE_TEXT ("<%C:%u> failed (%p)\n"),
                      uipmc_endpoint->host (),
                      uipmc_endpoint->port (),
                      ACE_TEXT ("errno")));

      return 0;
    }

  // Add the handler to Cache
  retval =
    this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc,
                                                                             transport);

  // Failure in adding to cache.
  if (retval == -1)
    {
      svc_handler->close ();

      if (TAO_debug_level)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) - UIPMC_Connector::")
                      ACE_TEXT ("make_connection, could not add the ")
                      ACE_TEXT ("new connection to cache\n")));
        }

      return 0;
    }

  svc_handler_auto_ptr.release ();
  return transport;
}
示例#4
0
TAO_Transport *
TAO_DIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *,
                                     TAO_Transport_Descriptor_Interface &desc,
                                     ACE_Time_Value * /*max_wait_time*/)
{
    TAO_DIOP_Endpoint *diop_endpoint =
        this->remote_endpoint (desc.endpoint ());

    if (diop_endpoint == 0)
        return 0;

    const ACE_INET_Addr &remote_address =
        diop_endpoint->object_addr ();

#if defined (ACE_HAS_IPV6) && !defined (ACE_HAS_IPV6_V6ONLY)
    // Check if we need to invalidate accepted connections
    // from IPv4 mapped IPv6 addresses
    if (this->orb_core ()->orb_params ()->connect_ipv6_only () &&
            remote_address.is_ipv4_mapped_ipv6 ())
    {
        if (TAO_debug_level > 0)
        {
            ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16];

            (void) remote_address.addr_to_string (remote_as_string,
                                                  sizeof remote_as_string);

            TAOLIB_ERROR ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) - DIOP_Connection_Handler::open, ")
                           ACE_TEXT ("invalid connection to IPv4 mapped IPv6 interface <%s>!\n"),
                           remote_as_string));
        }
        return 0;
    }
#endif /* ACE_HAS_IPV6 && ACE_HAS_IPV6_V6ONLY */

    TAO_DIOP_Connection_Handler *svc_handler = 0;

    ACE_NEW_RETURN (svc_handler,
                    TAO_DIOP_Connection_Handler (this->orb_core ()),
                    0);

    // Make sure that we always do a remove_reference
    ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler);

    u_short port = 0;
    const ACE_UINT32 ia_any = INADDR_ANY;
    ACE_INET_Addr local_addr (port, ia_any);

#if defined (ACE_HAS_IPV6)
    if (remote_address.get_type () == AF_INET6)
        local_addr.set (port,
                        ACE_IPV6_ANY);
#endif /* ACE_HAS_IPV6 */

    svc_handler->local_addr (local_addr);
    svc_handler->addr (remote_address);

    int retval = svc_handler->open (0);

    // Failure to open a connection.
    if (retval != 0)
    {
        svc_handler->close ();

        if (TAO_debug_level > 0)
        {
            TAOLIB_ERROR ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
                           ACE_TEXT ("could not make a new connection\n")));
        }

        return 0;
    }

    if (TAO_debug_level > 2)
        TAOLIB_DEBUG ((LM_DEBUG,
                       ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::connect, ")
                       ACE_TEXT ("new connection on HANDLE %d\n"),
                       svc_handler->peer ().get_handle ()));

    TAO_DIOP_Transport *transport =
        dynamic_cast <TAO_DIOP_Transport *> (svc_handler->transport ());

    // In case of errors transport is zero
    if (transport == 0)
    {
        svc_handler->close ();

        // Give users a clue to the problem.
        if (TAO_debug_level > 3)
            TAOLIB_DEBUG ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
                           ACE_TEXT ("connection to <%C:%u> failed (%p)\n"),
                           diop_endpoint->host (),
                           diop_endpoint->port (),
                           ACE_TEXT ("errno")));

        return 0;
    }

    // Add the handler to Cache
    retval =
        this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc,
                transport);

    // Failure in adding to cache.
    if (retval == -1)
    {
        svc_handler->close ();

        if (TAO_debug_level > 0)
        {
            TAOLIB_ERROR ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
                           ACE_TEXT ("could not add the new connection to cache\n")));
        }

        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;
}