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 79015 2007-07-24 15:03:04Z vridosh $")
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 u_short port = 0;
00131 const ACE_UINT32 ia_any = INADDR_ANY;
00132 ACE_INET_Addr local_addr(port, ia_any);
00133
00134 #if defined (ACE_HAS_IPV6)
00135 if (remote_address.get_type () == AF_INET6)
00136 local_addr.set (port,
00137 ACE_IPV6_ANY);
00138 #endif
00139
00140 svc_handler->local_addr (local_addr);
00141 svc_handler->addr (remote_address);
00142
00143 int retval = svc_handler->open (0);
00144
00145
00146 if (retval != 0)
00147 {
00148
00149 svc_handler->close ();
00150
00151 if (TAO_debug_level > 0)
00152 {
00153 ACE_ERROR ((LM_ERROR,
00154 "TAO (%P|%t) - UIPMC_Connector::make_connection, "
00155 "could not make a new connection\n"));
00156 }
00157
00158 return 0;
00159 }
00160
00161 if (TAO_debug_level > 2)
00162 ACE_DEBUG ((LM_DEBUG,
00163 ACE_TEXT ("TAO (%P|%t) - UIPMC_Connector::make_connection, ")
00164 ACE_TEXT ("new connection on HANDLE %d\n"),
00165 svc_handler->get_handle ()));
00166
00167 UIPMC_TRANSPORT *transport =
00168 dynamic_cast<UIPMC_TRANSPORT *> (svc_handler->transport ());
00169
00170
00171 if (transport == 0)
00172 {
00173
00174 svc_handler->close ();
00175
00176
00177 if (TAO_debug_level > 3)
00178 ACE_ERROR ((LM_ERROR,
00179 "TAO (%P|%t) - UIPMC_Connector::make_connection, "
00180 "connection to <%s:%u> failed (%p)\n",
00181 ACE_TEXT_CHAR_TO_TCHAR (uipmc_endpoint->host ()),
00182 uipmc_endpoint->port (),
00183 ACE_TEXT ("errno")));
00184
00185 return 0;
00186 }
00187
00188
00189 retval =
00190 this->orb_core ()->lane_resources ().transport_cache ().cache_transport (&desc,
00191 transport);
00192
00193
00194 if (retval != 0)
00195 {
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 return transport;
00210 }
00211
00212 TAO_Profile *
00213 TAO_UIPMC_Connector::create_profile (TAO_InputCDR& cdr)
00214 {
00215 TAO_Profile *pfile;
00216 ACE_NEW_RETURN (pfile,
00217 TAO_UIPMC_Profile (this->orb_core ()),
00218 0);
00219
00220 int r = pfile->decode (cdr);
00221 if (r == -1)
00222 {
00223 pfile->_decr_refcnt ();
00224 pfile = 0;
00225 }
00226
00227 return pfile;
00228 }
00229
00230 TAO_Profile *
00231 TAO_UIPMC_Connector::make_profile (void)
00232 {
00233
00234
00235
00236
00237
00238 TAO_Profile *profile = 0;
00239 ACE_NEW_THROW_EX (profile,
00240 TAO_UIPMC_Profile (this->orb_core ()),
00241 CORBA::NO_MEMORY (
00242 CORBA::SystemException::_tao_minor_code (
00243 TAO::VMCID,
00244 ENOMEM),
00245 CORBA::COMPLETED_NO));
00246
00247 return profile;
00248 }
00249
00250 int
00251 TAO_UIPMC_Connector::check_prefix (const char *endpoint)
00252 {
00253
00254 if (!endpoint || !*endpoint)
00255 return -1;
00256
00257 static const char protocol[] = "miop";
00258 static size_t const len = sizeof (protocol) - 1;
00259
00260 size_t const slot = ACE_OS::strchr (endpoint, ':') - endpoint;
00261
00262
00263
00264 if (slot == len
00265 && ACE_OS::strncasecmp (endpoint, protocol, len) == 0)
00266 return 0;
00267
00268 return -1;
00269
00270
00271 }
00272
00273 char
00274 TAO_UIPMC_Connector::object_key_delimiter (void) const
00275 {
00276 return TAO_UIPMC_Profile::object_key_delimiter_;
00277 }
00278
00279 int
00280 TAO_UIPMC_Connector::cancel_svc_handler (
00281 TAO_Connection_Handler * )
00282 {
00283
00284 return 0;
00285 }
00286
00287 TAO_END_VERSIONED_NAMESPACE_DECL
00288