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