Public Member Functions | Private Member Functions | Private Attributes | Friends

TAO_IIOP_Endpoint Class Reference

TAO_IIOP_Endpoint. More...

#include <IIOP_Endpoint.h>

Inheritance diagram for TAO_IIOP_Endpoint:
Inheritance graph
[legend]
Collaboration diagram for TAO_IIOP_Endpoint:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_IIOP_Endpoint (void)
 Default constructor.
 TAO_IIOP_Endpoint (const char *host, CORBA::UShort port, const ACE_INET_Addr &addr, CORBA::Short priority=TAO_INVALID_PRIORITY)
 TAO_IIOP_Endpoint (const ACE_INET_Addr &addr, int use_dotted_decimal_addresses)
 Constructor.
 TAO_IIOP_Endpoint (const char *host, CORBA::UShort port, CORBA::Short priority)
 Constructor. This constructor is used when decoding endpoints.
 ~TAO_IIOP_Endpoint (void)
 Destructor.
virtual TAO_Endpointnext (void)
 Endpoints can be linked in a list.
virtual TAO_Endpointnext_filtered (TAO_ORB_Core *, TAO_Endpoint *root)
virtual int addr_to_string (char *buffer, size_t length)
 Return a string representation for the address.
virtual TAO_Endpointduplicate (void)
 Makes a copy of this.
virtual CORBA::Boolean is_equivalent (const TAO_Endpoint *other_endpoint)
virtual CORBA::ULong hash (void)
 Return a hash value for this object.
const ACE_INET_Addrobject_addr (void) const
 Return a reference to the <object_addr>.
const char * host (void) const
const char * host (const char *h)
CORBA::UShort port (void) const
 Return the port number.
CORBA::UShort port (CORBA::UShort p)
 Set the port number.
bool is_preferred_network (void) const
 Do we have a preferred local network for the target?
const char * preferred_network (void) const
 Return the preferred network if any.
TAO_IIOP_Endpointoperator= (const TAO_IIOP_Endpoint &other)

Private Member Functions

TAO_IIOP_Endpointnext_filtered_i (TAO_IIOP_Endpoint *root, bool ipv6_only, bool prefer_ipv6, bool want_ipv6)
int set (const ACE_INET_Addr &addr, int use_dotted_decimal_addresses)
 Helper method for setting INET_Addr.
void object_addr_i (void) const
 Helper method for object_addr () call.
CORBA::ULong preferred_interfaces (const char *csvPreferred, bool enforce, TAO_IIOP_Profile &profile)
TAO_IIOP_Endpointadd_local_endpoint (TAO_IIOP_Endpoint *ep, const char *local, TAO_IIOP_Profile &profile)
 TAO_IIOP_Endpoint (const TAO_IIOP_Endpoint &)
 Canonical copy constructor.

Private Attributes

CORBA::String_var host_
 String representing the host name.
CORBA::UShort port_
 TCP port number.
bool is_encodable_
 Is this endpoint created encodable as part of the IOR?
bool object_addr_set_
 Flag to indicate if the address has been resolved and set.
ACE_INET_Addr object_addr_
TAO::IIOP_Endpoint_Info preferred_path_
 Preferred path for this endpoint.
TAO_IIOP_Endpointnext_

Friends

class TAO_IIOP_Profile
class TAO_SSLIOP_Profile

Detailed Description

TAO_IIOP_Endpoint.

IIOP-specific implementation of PP Framework Endpoint interface.

Definition at line 46 of file IIOP_Endpoint.h.


Constructor & Destructor Documentation

TAO_IIOP_Endpoint::TAO_IIOP_Endpoint ( void   ) 

Default constructor.

Definition at line 78 of file IIOP_Endpoint.cpp.

  : TAO_Endpoint (IOP::TAG_INTERNET_IOP)
  , host_ ()
  , port_ (683)  // default port (IANA assigned)
#if defined (ACE_HAS_IPV6)
  , is_ipv6_decimal_ (false)
#endif /* ACE_HAS_IPV6 */
  , is_encodable_ (true)
  , object_addr_set_ (false)
  , object_addr_ ()
  , preferred_path_ ()
  , next_ (0)
{
}

TAO_IIOP_Endpoint::TAO_IIOP_Endpoint ( const char *  host,
CORBA::UShort  port,
const ACE_INET_Addr addr,
CORBA::Short  priority = TAO_INVALID_PRIORITY 
)

Constructor. This is the most efficient constructor since it does not require any address resolution processing.

Definition at line 59 of file IIOP_Endpoint.cpp.

  : TAO_Endpoint (IOP::TAG_INTERNET_IOP, priority)
  , host_ ()
  , port_ (port)
#if defined (ACE_HAS_IPV6)
  , is_ipv6_decimal_ (false)
#endif /* ACE_HAS_IPV6 */
  , is_encodable_ (true)
  , object_addr_set_ (false)
  , object_addr_ (addr)
  , preferred_path_ ()
  , next_ (0)
{
  this->host(host); // With IPv6 performs check for decimal address
}

TAO_IIOP_Endpoint::TAO_IIOP_Endpoint ( const ACE_INET_Addr addr,
int  use_dotted_decimal_addresses 
)

Constructor.

Definition at line 42 of file IIOP_Endpoint.cpp.

  : TAO_Endpoint (IOP::TAG_INTERNET_IOP)
  , host_ ()
  , port_ (683) // default port (IANA assigned)
#if defined (ACE_HAS_IPV6)
  , is_ipv6_decimal_ (false)
#endif /* ACE_HAS_IPV6 */
  , is_encodable_ (true)
  , object_addr_set_ (false)
  , object_addr_ (addr)
  , preferred_path_ ()
  , next_ (0)
{
  this->set (addr, use_dotted_decimal_addresses);
}

TAO_IIOP_Endpoint::TAO_IIOP_Endpoint ( const char *  host,
CORBA::UShort  port,
CORBA::Short  priority 
)

Constructor. This constructor is used when decoding endpoints.

Definition at line 93 of file IIOP_Endpoint.cpp.

  : TAO_Endpoint (IOP::TAG_INTERNET_IOP, priority)
  , host_ ()
  , port_ (port)
#if defined (ACE_HAS_IPV6)
  , is_ipv6_decimal_ (false)
#endif /* ACE_HAS_IPV6 */
  , is_encodable_ (true)
  , object_addr_set_ (false)
  , object_addr_ ()
  , preferred_path_ ()
  , next_ (0)
{
  this->host(host); // With IPv6 performs check for decimal address
}

TAO_IIOP_Endpoint::~TAO_IIOP_Endpoint ( void   ) 

Destructor.

Definition at line 132 of file IIOP_Endpoint.cpp.

{
}

TAO_IIOP_Endpoint::TAO_IIOP_Endpoint ( const TAO_IIOP_Endpoint rhs  )  [private]

Canonical copy constructor.

In private section to prevent clients from invoking this accidentally. Clients should only use duplicate () to make a deep copy

Definition at line 138 of file IIOP_Endpoint.cpp.

  : TAO_Endpoint (rhs.tag_, rhs.priority_)
  , host_ (rhs.host_)
  , port_ (rhs.port_)
#if defined (ACE_HAS_IPV6)
  , is_ipv6_decimal_ (rhs.is_ipv6_decimal_)
#endif /* ACE_HAS_IPV6 */
  , is_encodable_ (rhs.is_encodable_)
  , object_addr_set_ (rhs.object_addr_set_)
  , object_addr_ (rhs.object_addr_)
  , preferred_path_  (rhs.preferred_path_)
  , next_ (0)
{
}


Member Function Documentation

TAO_IIOP_Endpoint * TAO_IIOP_Endpoint::add_local_endpoint ( TAO_IIOP_Endpoint ep,
const char *  local,
TAO_IIOP_Profile profile 
) [private]

Chain a new duplicate of ourself with the specified local preferred interface.

Definition at line 416 of file IIOP_Endpoint.cpp.

{
  TAO_IIOP_Endpoint *tmp = static_cast<TAO_IIOP_Endpoint *> (ep->duplicate ());
  tmp->is_encodable_ = true;
  tmp->preferred_path_.host = local;
  profile.add_endpoint (tmp);
  return tmp;
}

int TAO_IIOP_Endpoint::addr_to_string ( char *  buffer,
size_t  length 
) [virtual]

Return a string representation for the address.

The purpose of this method is to provide a general interface to the underlying address object's addr_to_string method. This allows the protocol implementor to select the appropriate string format.

Returns:
-1 if buffer is too small.

Implements TAO_Endpoint.

Definition at line 204 of file IIOP_Endpoint.cpp.

{
  size_t actual_len =
    ACE_OS::strlen (this->host_.in ()) // chars in host name
    + sizeof (':')                     // delimiter
    + ACE_OS::strlen ("65536")         // max port
    + sizeof ('\0');

#if defined (ACE_HAS_IPV6)
  if (this->is_ipv6_decimal_)
    actual_len += 2; // '[' + ']'
#endif /* ACE_HAS_IPV6 */

  if (length < actual_len)
    return -1;

#if defined (ACE_HAS_IPV6)
  if (this->is_ipv6_decimal_)
    ACE_OS::sprintf (buffer, "[%s]:%d",
                     this->host_.in (), this->port_);
  else
#endif /* ACE_HAS_IPV6 */
  ACE_OS::sprintf (buffer, "%s:%d",
                   this->host_.in (), this->port_);

  return 0;
}

TAO_Endpoint * TAO_IIOP_Endpoint::duplicate ( void   )  [virtual]

Makes a copy of this.

Implements TAO_Endpoint.

Definition at line 320 of file IIOP_Endpoint.cpp.

{
  TAO_IIOP_Endpoint *endpoint = 0;

  // @@ NOTE: Not exception safe..
  ACE_NEW_RETURN (endpoint, TAO_IIOP_Endpoint (*this), 0);

  return endpoint;
}

CORBA::ULong TAO_IIOP_Endpoint::hash ( void   )  [virtual]

Return a hash value for this object.

Implements TAO_Endpoint.

Definition at line 570 of file IIOP_Endpoint.cpp.

{
  if (this->hash_val_ != 0)
    return this->hash_val_;

  {
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                      guard,
                      this->addr_lookup_lock_,
                      this->hash_val_);
    // .. DCL
    if (this->hash_val_ != 0)
      return this->hash_val_;

    // A few comments about this optimization. The call below will
    // deadlock if the object_addr_set is false. If you don't belive

    if (!this->object_addr_set_)
      {
        // Set the object_addr first
        (void) this->object_addr_i ();
      }

    this->hash_val_ = this->object_addr_.hash ();
  }

  return this->hash_val_;
}

const char * TAO_IIOP_Endpoint::host ( const char *  h  ) 

Copy the string <h> into <host_> and return the resulting pointer. This object maintains ownership of this string.

Definition at line 233 of file IIOP_Endpoint.cpp.

{
  this->host_ = h;
#if defined (ACE_HAS_IPV6)
  if (ACE_OS::strchr (h, ':') != 0)
    this->is_ipv6_decimal_ = true;
#endif /* ACE_HAS_IPV6 */

  return this->host_.in ();
}

const char* TAO_IIOP_Endpoint::host ( void   )  const

Return a pointer to the host string. This object maintains ownership of this string.

CORBA::Boolean TAO_IIOP_Endpoint::is_equivalent ( const TAO_Endpoint other_endpoint  )  [virtual]

Return true if this endpoint is equivalent to other_endpoint. Two endpoints are equivalent if their port and host are the same.

Implements TAO_Endpoint.

Definition at line 557 of file IIOP_Endpoint.cpp.

{
  const TAO_IIOP_Endpoint *endpoint =
    dynamic_cast<const TAO_IIOP_Endpoint *> (other_endpoint);

  if (endpoint == 0)
    return 0;

  return (this->port_ == endpoint->port_
          && (ACE_OS::strcmp (this->host (), endpoint->host ()) == 0));
}

bool TAO_IIOP_Endpoint::is_preferred_network ( void   )  const

Do we have a preferred local network for the target?

Definition at line 600 of file IIOP_Endpoint.cpp.

{
  return (this->preferred_path_.host.in () != 0 &&
          this->preferred_path_.host.in ()[0] != 0);
}

TAO_Endpoint * TAO_IIOP_Endpoint::next ( void   )  [virtual]

Endpoints can be linked in a list.

Returns:
The next endpoint in the list, if any.

Implements TAO_Endpoint.

Definition at line 245 of file IIOP_Endpoint.cpp.

{
  return this->next_;
}

TAO_Endpoint * TAO_IIOP_Endpoint::next_filtered ( TAO_ORB_Core orb_core,
TAO_Endpoint root 
) [virtual]

Return the next endpoint in the list, but use protocol-specific filtering to constrain the value. The orb core is needed to supply any sort of filter arguments, and the root endpoint is needed in case the algorithm needs to rewind. If the supplied root is 0, then this is assumed to be the candidate next endpoint.

To use this, the caller starts off the change with root == 0. This is a bit of a violation in logic, a more correct implementation would accept this == 0 and a non-null root. To do iteration using next_filtered, do: for (TAO_Endpoint *ep = root_endpoint->next_filtered (orb_core, 0); ep != 0; ep = ep->next_filtered(orb_core, root_endpoint)) { }

Reimplemented from TAO_Endpoint.

Definition at line 251 of file IIOP_Endpoint.cpp.

{
  bool want_ipv6 = false;
  bool ipv6_only = false;
  bool prefer_ipv6 = false;
#if defined (ACE_HAS_IPV6)
  want_ipv6 = true;
  ipv6_only = orb_core->orb_params()->connect_ipv6_only();
  prefer_ipv6 = orb_core->orb_params()->prefer_ipv6_interfaces();
#else
  ACE_UNUSED_ARG (orb_core);
#endif /* ACE_HAS_IPV6 */
  return
    this->next_filtered_i (static_cast<TAO_IIOP_Endpoint *>(root),
                           ipv6_only,
                           prefer_ipv6,
                           want_ipv6);
}

TAO_IIOP_Endpoint * TAO_IIOP_Endpoint::next_filtered_i ( TAO_IIOP_Endpoint root,
bool  ipv6_only,
bool  prefer_ipv6,
bool  want_ipv6 
) [private]

Definition at line 271 of file IIOP_Endpoint.cpp.

{
  // the candidate is nominally the next entry in the list, but since
  // the list may loop back on itself, the root of the list needs to be
  // initialized.
  TAO_IIOP_Endpoint *candidate = (root == 0) ? this : next_;
  if (root == 0)
    root = this;

#if defined (ACE_HAS_IPV6)
  if (ipv6_only)
    {
      if (candidate == 0 || candidate->is_ipv6_decimal())
        return candidate;
      const ACE_INET_Addr &addr = candidate->object_addr ();
      bool allowed = addr.get_type () == AF_INET6 &&
        !addr.is_ipv4_mapped_ipv6();

      return allowed ? candidate :
        candidate->next_filtered_i(root, ipv6_only, prefer_ipv6, true);
    }
  if (prefer_ipv6)
    {
      if (candidate == 0)
        return !want_ipv6 ? candidate :
          root->next_filtered_i(root, ipv6_only, prefer_ipv6, false);

      if (want_ipv6 == candidate->is_ipv6_decimal())
        return candidate;

      const ACE_INET_Addr &addr = candidate->object_addr ();
      bool really_ipv6 = addr.get_type () == AF_INET6 &&
                         !addr.is_ipv4_mapped_ipv6();
      return (want_ipv6 == really_ipv6) ? candidate :
        candidate->next_filtered_i(root, ipv6_only, prefer_ipv6, want_ipv6);
    }
#else
  ACE_UNUSED_ARG (want_ipv6);
  ACE_UNUSED_ARG (ipv6_only);
  ACE_UNUSED_ARG (prefer_ipv6);
#endif

  return candidate;
}

const ACE_INET_Addr & TAO_IIOP_Endpoint::object_addr ( void   )  const

Return a reference to the <object_addr>.

Definition at line 331 of file IIOP_Endpoint.cpp.

{
  // The object_addr_ is initialized here, rather than at IOR decode
  // time for several reasons:
  //   1. A request on the object may never be invoked.
  //   2. The DNS setup may have changed dynamically.
  //   ...etc..

  // Double checked locking optimization.
  if (!this->object_addr_set_)
    {
      ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                        guard,
                        this->addr_lookup_lock_,
                        this->object_addr_);

      if (!this->object_addr_set_)
        {
          (void) this->object_addr_i ();
        }
    }

  return this->object_addr_;
}

void TAO_IIOP_Endpoint::object_addr_i ( void   )  const [private]

Helper method for object_addr () call.

Definition at line 357 of file IIOP_Endpoint.cpp.

{
  // We should have already held the lock

#if defined (ACE_HAS_IPV6)
  bool is_ipv4_decimal_ = false;
  if (!this->is_ipv6_decimal_)
    is_ipv4_decimal_ =
      ACE_OS::strspn (this->host_.in (), ".0123456789") ==
                              ACE_OS::strlen (this->host_.in ());

  // If this is *not* an IPv4 decimal address at first try to
  // resolve the address as an IPv6 address; if that fails
  // (or it's an IPv4 address) and the address is *not* an IPv6
  // decimal address try to resolve it as an IPv4 address.
  if ((is_ipv4_decimal_ ||
        this->object_addr_.set (this->port_,
                                this->host_.in (),
                                1,
                                AF_INET6) == -1) &&
      (this->is_ipv6_decimal_ ||
        this->object_addr_.set (this->port_,
                              this->host_.in (),
                              1,
                              AF_INET) == -1))
#else
  if (this->object_addr_.set (this->port_,
                              this->host_.in ()) == -1)
#endif
    {
      // If this call fails, it most likely due a hostname
      // lookup failure caused by a DNS misconfiguration.  If
      // a request is made to the object at the given host and
      // port, then a CORBA::TRANSIENT() exception should be
      // thrown.

      // Invalidate the ACE_INET_Addr.  This is used as a flag
      // to denote that ACE_INET_Addr initialization failed.
      this->object_addr_.set_type (-1);
    }
  else
    {
      this->object_addr_set_ = true;
    }
}

TAO_IIOP_Endpoint & TAO_IIOP_Endpoint::operator= ( const TAO_IIOP_Endpoint other  ) 

Need to have an assignment operator since the IIOP_Profile class may have to reorder its list of endpoints based on filtering by the EndpointPolicy.

Definition at line 114 of file IIOP_Endpoint.cpp.

{
  if (this != &other)
    {
      this->host_ = other.host_;
      this->port_ = other.port_;
#if defined (ACE_HAS_IPV6)
      this->is_ipv6_decimal_ = other.is_ipv6_decimal_;
#endif /* ACE_HAS_IPV6 */
      this->is_encodable_  = other.is_encodable_;
      this->object_addr_set_ = other.object_addr_set_;
      this->object_addr_ = other.object_addr_;
      this->preferred_path_ = other.preferred_path_;
      this->next_ = 0; // do not copy list membership, since we are only cloning the values
    }
  return *this;
}

CORBA::UShort TAO_IIOP_Endpoint::port ( CORBA::UShort  p  ) 

Set the port number.

CORBA::UShort TAO_IIOP_Endpoint::port ( void   )  const

Return the port number.

CORBA::ULong TAO_IIOP_Endpoint::preferred_interfaces ( const char *  csvPreferred,
bool  enforce,
TAO_IIOP_Profile profile 
) [private]

Generate preferred interfaces from the options passed in by the user.

Definition at line 525 of file IIOP_Endpoint.cpp.

{
  ACE_Vector<ACE_CString> preferred;
  find_preferred_interfaces(this->host_.in(), csv, preferred);
  CORBA::ULong count = preferred.size();
  if (count > 0)
  {
    this->is_encodable_ = true;
    this->preferred_path_.host = CORBA::string_dup(preferred[0].c_str());
    TAO_IIOP_Endpoint* ep = this;
    for (size_t i = 1; i < count; ++i)
    {
      ep = add_local_endpoint (ep, preferred[i].c_str(), profile);
    }

    // If we're not enforcing the preferred interfaces, then we can just add
    // a new non-preferred endpoint to the end with a default local addr.
    if (! enforce)
    {
      ep = add_local_endpoint (ep, "", profile);
    }
    else
    {
      --count;
    }
  }
  return count;
}

const char * TAO_IIOP_Endpoint::preferred_network ( void   )  const

Return the preferred network if any.

Definition at line 607 of file IIOP_Endpoint.cpp.

{
  return this->preferred_path_.host.in ();
}

int TAO_IIOP_Endpoint::set ( const ACE_INET_Addr addr,
int  use_dotted_decimal_addresses 
) [private]

Helper method for setting INET_Addr.

Definition at line 154 of file IIOP_Endpoint.cpp.

{
  char tmp_host[MAXHOSTNAMELEN + 1];

#if defined (ACE_HAS_IPV6)
  this->is_ipv6_decimal_ = false; // Reset
#endif /* ACE_HAS_IPV6 */

  if (use_dotted_decimal_addresses
      || addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
    {
      if (use_dotted_decimal_addresses == 0 && TAO_debug_level > 5)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - IIOP_Endpoint::set, ")
                      ACE_TEXT ("%p\n"),
                      ACE_TEXT ("cannot determine hostname")));
        }

      const char *tmp = addr.get_host_addr ();
      if (tmp == 0)
        {
          if (TAO_debug_level > 0)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO (%P|%t) - IIOP_Endpoint::set, ")
                          ACE_TEXT ("%p\n"),
                          ACE_TEXT ("cannot determine hostname and hostaddr")));
            }
          return -1;
        }
      else
        {
          this->host_ = tmp;
#if defined (ACE_HAS_IPV6)
          if (addr.get_type () == PF_INET6)
            this->is_ipv6_decimal_ = true;
#endif /* ACE_HAS_IPV6 */
        }
    }
  else
    this->host_ = CORBA::string_dup (tmp_host);

  this->port_ = addr.get_port_number();

  return 0;
}


Friends And Related Function Documentation

friend class TAO_IIOP_Profile [friend]

Definition at line 53 of file IIOP_Endpoint.h.

friend class TAO_SSLIOP_Profile [friend]

Definition at line 54 of file IIOP_Endpoint.h.


Member Data Documentation

String representing the host name.

Definition at line 200 of file IIOP_Endpoint.h.

Is this endpoint created encodable as part of the IOR?

Definition at line 211 of file IIOP_Endpoint.h.

IIOP Endpoints can be stringed into a list. Return the next endpoint in the list, if any.

Definition at line 225 of file IIOP_Endpoint.h.

Cached instance of ACE_INET_Addr for use in making invocations, etc.

Definition at line 218 of file IIOP_Endpoint.h.

bool TAO_IIOP_Endpoint::object_addr_set_ [mutable, private]

Flag to indicate if the address has been resolved and set.

Definition at line 214 of file IIOP_Endpoint.h.

TCP port number.

Definition at line 203 of file IIOP_Endpoint.h.

TAO::IIOP_Endpoint_Info TAO_IIOP_Endpoint::preferred_path_ [private]

Preferred path for this endpoint.

Definition at line 221 of file IIOP_Endpoint.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines