Go to the documentation of this file.00001
00002
00003
00004 #include "tao/Strategies/DIOP_Connector.h"
00005
00006 #if defined (TAO_HAS_DIOP) && (TAO_HAS_DIOP != 0)
00007
00008 #include "ace/Connector.h"
00009
00010 #include "tao/debug.h"
00011 #include "tao/ORB_Core.h"
00012 #include "tao/SystemException.h"
00013 #include "tao/Base_Transport_Property.h"
00014 #include "tao/Protocols_Hooks.h"
00015 #include "ace/OS_NS_strings.h"
00016 #include "ace/OS_NS_string.h"
00017 #include "tao/Thread_Lane_Resources.h"
00018 #include "ace/os_include/os_netdb.h"
00019
00020 #include "tao/Strategies/DIOP_Profile.h"
00021
00022
00023 ACE_RCSID (Strategies,
00024 DIOP_Connector,
00025 "$Id: DIOP_Connector.cpp 86593 2009-09-02 14:58:00Z vzykov $")
00026
00027
00028 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00029
00030 TAO_DIOP_Connector::TAO_DIOP_Connector (void)
00031 : TAO_Connector (TAO_TAG_DIOP_PROFILE)
00032 {
00033 }
00034
00035 TAO_DIOP_Connector::~TAO_DIOP_Connector (void)
00036 {
00037 }
00038
00039 int
00040 TAO_DIOP_Connector::open (TAO_ORB_Core *orb_core)
00041 {
00042 this->orb_core (orb_core);
00043
00044
00045 if (this->create_connect_strategy () == -1)
00046 return -1;
00047
00048 return 0;
00049 }
00050
00051 int
00052 TAO_DIOP_Connector::close (void)
00053 {
00054 return 0;
00055 }
00056
00057 int
00058 TAO_DIOP_Connector::set_validate_endpoint (TAO_Endpoint *endpoint)
00059 {
00060 TAO_DIOP_Endpoint *diop_endpoint =
00061 this->remote_endpoint (endpoint);
00062
00063 if (diop_endpoint == 0)
00064 return -1;
00065
00066 const ACE_INET_Addr &remote_address =
00067 diop_endpoint->object_addr ();
00068
00069
00070
00071
00072 #if defined (ACE_HAS_IPV6)
00073 if (remote_address.get_type () != AF_INET &&
00074 remote_address.get_type () != AF_INET6)
00075 #else
00076 if (remote_address.get_type () != AF_INET)
00077 #endif
00078 {
00079 if (TAO_debug_level > 0)
00080 {
00081 ACE_DEBUG ((LM_DEBUG,
00082 ACE_TEXT ("TAO (%P|%t) - DIOP connection failed.\n")
00083 ACE_TEXT ("TAO (%P|%t) This is most likely ")
00084 ACE_TEXT ("due to a hostname lookup ")
00085 ACE_TEXT ("failure.\n")));
00086 }
00087
00088 return -1;
00089 }
00090
00091 return 0;
00092 }
00093
00094 TAO_Transport *
00095 TAO_DIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *,
00096 TAO_Transport_Descriptor_Interface &desc,
00097 ACE_Time_Value * )
00098 {
00099 TAO_DIOP_Endpoint *diop_endpoint =
00100 this->remote_endpoint (desc.endpoint ());
00101
00102 if (diop_endpoint == 0)
00103 return 0;
00104
00105 const ACE_INET_Addr &remote_address =
00106 diop_endpoint->object_addr ();
00107
00108 #if defined (ACE_HAS_IPV6) && !defined (ACE_HAS_IPV6_V6ONLY)
00109
00110
00111 if (this->orb_core ()->orb_params ()->connect_ipv6_only () &&
00112 remote_address.is_ipv4_mapped_ipv6 ())
00113 {
00114 if (TAO_debug_level > 0)
00115 {
00116 ACE_TCHAR remote_as_string[MAXHOSTNAMELEN + 16];
00117
00118 (void) remote_address.addr_to_string (remote_as_string,
00119 sizeof remote_as_string);
00120
00121 ACE_ERROR ((LM_ERROR,
00122 ACE_TEXT ("TAO (%P|%t) - DIOP_Connection_Handler::open, ")
00123 ACE_TEXT ("invalid connection to IPv4 mapped IPv6 interface <%s>!\n"),
00124 remote_as_string));
00125 }
00126 return 0;
00127 }
00128 #endif
00129
00130 TAO_DIOP_Connection_Handler *svc_handler = 0;
00131
00132 ACE_NEW_RETURN (svc_handler,
00133 TAO_DIOP_Connection_Handler (this->orb_core ()),
00134 0);
00135
00136
00137 ACE_Event_Handler_var svc_handler_auto_ptr (svc_handler);
00138
00139 u_short port = 0;
00140 const ACE_UINT32 ia_any = INADDR_ANY;
00141 ACE_INET_Addr local_addr (port, ia_any);
00142
00143 #if defined (ACE_HAS_IPV6)
00144 if (remote_address.get_type () == AF_INET6)
00145 local_addr.set (port,
00146 ACE_IPV6_ANY);
00147 #endif
00148
00149 svc_handler->local_addr (local_addr);
00150 svc_handler->addr (remote_address);
00151
00152 int retval = svc_handler->open (0);
00153
00154
00155 if (retval != 0)
00156 {
00157 svc_handler->close ();
00158
00159 if (TAO_debug_level > 0)
00160 {
00161 ACE_ERROR ((LM_ERROR,
00162 ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
00163 ACE_TEXT ("could not make a new connection\n")));
00164 }
00165
00166 return 0;
00167 }
00168
00169 if (TAO_debug_level > 2)
00170 ACE_DEBUG ((LM_DEBUG,
00171 ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::connect, ")
00172 ACE_TEXT ("new connection on HANDLE %d\n"),
00173 svc_handler->peer ().get_handle ()));
00174
00175 TAO_DIOP_Transport *transport =
00176 dynamic_cast <TAO_DIOP_Transport *> (svc_handler->transport ());
00177
00178
00179 if (transport == 0)
00180 {
00181 svc_handler->close ();
00182
00183
00184 if (TAO_debug_level > 3)
00185 ACE_DEBUG ((LM_ERROR,
00186 ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
00187 ACE_TEXT ("connection to <%C:%u> failed (%p)\n"),
00188 diop_endpoint->host (),
00189 diop_endpoint->port (),
00190 ACE_TEXT ("errno")));
00191
00192 return 0;
00193 }
00194
00195
00196 retval =
00197 this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc,
00198 transport);
00199
00200
00201 if (retval == -1)
00202 {
00203 svc_handler->close ();
00204
00205 if (TAO_debug_level > 0)
00206 {
00207 ACE_ERROR ((LM_ERROR,
00208 ACE_TEXT ("TAO (%P|%t) - DIOP_Connector::make_connection, ")
00209 ACE_TEXT ("could not add the new connection to cache\n")));
00210 }
00211
00212 return 0;
00213 }
00214
00215 svc_handler_auto_ptr.release ();
00216 return transport;
00217 }
00218
00219 TAO_Profile *
00220 TAO_DIOP_Connector::create_profile (TAO_InputCDR& cdr)
00221 {
00222 TAO_Profile *pfile = 0;
00223 ACE_NEW_RETURN (pfile,
00224 TAO_DIOP_Profile (this->orb_core ()),
00225 0);
00226
00227 if (pfile->decode (cdr) == -1)
00228 {
00229 pfile->_decr_refcnt ();
00230 pfile = 0;
00231 }
00232
00233 return pfile;
00234 }
00235
00236 TAO_Profile *
00237 TAO_DIOP_Connector::make_profile (void)
00238 {
00239
00240
00241
00242
00243
00244 TAO_Profile *profile = 0;
00245 ACE_NEW_THROW_EX (profile,
00246 TAO_DIOP_Profile (this->orb_core ()),
00247 CORBA::NO_MEMORY (
00248 CORBA::SystemException::_tao_minor_code (
00249 TAO::VMCID,
00250 ENOMEM),
00251 CORBA::COMPLETED_NO));
00252
00253 return profile;
00254 }
00255
00256 int
00257 TAO_DIOP_Connector::check_prefix (const char *endpoint)
00258 {
00259
00260 if (!endpoint || !*endpoint)
00261 return -1;
00262
00263 const char *protocol[] = { "diop", "dioploc" };
00264
00265 size_t const slot = ACE_OS::strchr (endpoint, ':') - endpoint;
00266
00267 size_t const len0 = ACE_OS::strlen (protocol[0]);
00268 size_t const len1 = ACE_OS::strlen (protocol[1]);
00269
00270
00271
00272 if (slot == len0
00273 && ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0)
00274 return 0;
00275 else if (slot == len1
00276 && ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0)
00277 return 0;
00278
00279 return -1;
00280
00281
00282 }
00283
00284 char
00285 TAO_DIOP_Connector::object_key_delimiter (void) const
00286 {
00287 return TAO_DIOP_Profile::object_key_delimiter_;
00288 }
00289
00290 TAO_DIOP_Endpoint *
00291 TAO_DIOP_Connector::remote_endpoint (TAO_Endpoint *endpoint)
00292 {
00293 if (endpoint->tag () != TAO_TAG_DIOP_PROFILE)
00294 return 0;
00295
00296 return dynamic_cast<TAO_DIOP_Endpoint *> (endpoint);
00297 }
00298
00299 int
00300 TAO_DIOP_Connector::cancel_svc_handler (
00301 TAO_Connection_Handler * )
00302 {
00303 return 0;
00304 }
00305
00306 TAO_END_VERSIONED_NAMESPACE_DECL
00307
00308 #endif