1 #include "tao/Strategies/SHMIOP_Endpoint.h"
3 #if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)
5 #include "tao/Strategies/SHMIOP_Connection_Handler.h"
7 #include "tao/ORB_Constants.h"
9 #include "ace/OS_NS_stdio.h"
11 #if !defined (__ACE_INLINE__)
12 # include "tao/Strategies/SHMIOP_Endpoint.inl"
13 #endif /* __ACE_INLINE__ */
15 #include "ace/os_include/os_netdb.h"
18 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
20 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const ACE_MEM_Addr
&addr
,
21 int use_dotted_decimal_addresses
)
22 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE
)
25 , object_addr_ (addr
.get_remote_addr ())
26 , object_addr_set_ (0)
29 this->set (addr
.get_remote_addr (), use_dotted_decimal_addresses
);
32 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const ACE_INET_Addr
&addr
,
33 int use_dotted_decimal_addresses
)
34 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE
)
38 , object_addr_set_ (0)
41 this->set (addr
, use_dotted_decimal_addresses
);
44 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host
,
46 const ACE_INET_Addr
&addr
,
47 CORBA::Short priority
)
48 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE
, priority
)
52 , object_addr_set_ (0)
59 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint ()
60 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE
)
64 , object_addr_set_ (0)
69 TAO_SHMIOP_Endpoint::TAO_SHMIOP_Endpoint (const char *host
,
71 CORBA::Short priority
)
72 : TAO_Endpoint (TAO_TAG_SHMEM_PROFILE
)
76 , object_addr_set_ (0)
82 this->priority (priority
);
85 TAO_SHMIOP_Endpoint::~TAO_SHMIOP_Endpoint ()
90 TAO_SHMIOP_Endpoint::set (const ACE_INET_Addr
&addr
,
91 int use_dotted_decimal_addresses
)
93 char tmp_host
[MAXHOSTNAMELEN
+ 1];
95 if (use_dotted_decimal_addresses
96 || addr
.get_host_name (tmp_host
, sizeof (tmp_host
)) != 0)
98 if (use_dotted_decimal_addresses
== 0 && TAO_debug_level
> 5)
100 TAOLIB_DEBUG ((LM_DEBUG
,
101 ACE_TEXT ("TAO (%P|%t) - SHMIOP_Endpoint::set, ")
102 ACE_TEXT ("- %p cannot determine hostname\n")));
105 const char *tmp
= addr
.get_host_addr ();
108 if (TAO_debug_level
> 0)
109 TAOLIB_DEBUG ((LM_DEBUG
,
110 ACE_TEXT ("TAO (%P|%t) - ")
111 ACE_TEXT ("SHMIOP_Endpoint::set ")
113 ACE_TEXT ("cannot determine hostname")));
120 this->host_
= CORBA::string_dup (tmp_host
);
122 this->port_
= addr
.get_port_number();
128 TAO_SHMIOP_Endpoint::addr_to_string (char *buffer
, size_t length
)
131 ACE_OS::strlen (this->host_
.in ()) // chars in host name
132 + sizeof (':') // delimiter
133 + std::strlen ("65536") // max port
136 if (length
< actual_len
)
139 ACE_OS::sprintf (buffer
, "%s:%d",
140 this->host_
.in (), this->port_
);
146 TAO_SHMIOP_Endpoint::host (const char *h
)
150 return this->host_
.in ();
154 TAO_SHMIOP_Endpoint::next ()
160 TAO_SHMIOP_Endpoint::duplicate ()
162 TAO_SHMIOP_Endpoint
*endpoint
= 0;
163 ACE_NEW_RETURN (endpoint
,
164 TAO_SHMIOP_Endpoint (this->host_
.in (),
175 TAO_SHMIOP_Endpoint::is_equivalent (const TAO_Endpoint
*other_endpoint
)
177 const TAO_SHMIOP_Endpoint
*endpoint
= dynamic_cast <const TAO_SHMIOP_Endpoint
*>
184 this->port_
== endpoint
->port_
185 && ACE_OS::strcmp (this->host_
.in (), endpoint
->host_
.in ()) == 0;
189 TAO_SHMIOP_Endpoint::hash ()
191 if (this->hash_val_
!= 0)
192 return this->hash_val_
;
195 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
197 this->addr_lookup_lock_
,
200 if (this->hash_val_
!= 0)
201 return this->hash_val_
;
204 ACE::hash_pjw (this->host ()) + this->port ();
207 return this->hash_val_
;
210 const ACE_INET_Addr
&
211 TAO_SHMIOP_Endpoint::object_addr () const
213 // The object_addr_ is initialized here, rather than at IOR decode
214 // time for several reasons:
215 // 1. A request on the object may never be invoked.
216 // 2. The DNS setup may have changed dynamically.
219 // Double checked locking optimization.
220 if (!this->object_addr_set_
)
222 // We need to modify the object_addr_ in this method. Do so
223 // using a non-const copy of the <this> pointer.
224 TAO_SHMIOP_Endpoint
*endpoint
=
225 const_cast <TAO_SHMIOP_Endpoint
*>(this);
227 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
,
229 endpoint
->addr_lookup_lock_
,
230 this->object_addr_
);
232 if (!this->object_addr_set_
)
234 if (endpoint
->object_addr_
.set (this->port_
,
235 this->host_
.in ()) == -1)
237 // If this call fails, it most likely due a hostname
238 // lookup failure caused by a DNS misconfiguration. If
239 // a request is made to the object at the given host and
240 // port, then a CORBA::TRANSIENT() exception should be
243 // Invalidate the ACE_INET_Addr. This is used as a flag
244 // to denote that ACE_INET_Addr initialization failed.
245 endpoint
->object_addr_
.set_type (-1);
249 endpoint
->object_addr_set_
= 1;
254 return this->object_addr_
;
257 TAO_END_VERSIONED_NAMESPACE_DECL
259 #endif /* TAO_HAS_SHMIOP && TAO_HAS_SHMIOP != 0 */