diff options
author | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-05 19:13:14 +0000 |
---|---|---|
committer | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2001-09-05 19:13:14 +0000 |
commit | 1b1499ded161f2ed308908bcfd48d97e2fa4424c (patch) | |
tree | eb02a8fd8675112d8b070a0a5ba33b65b0aa637f | |
parent | 05b459a2a0b9e9a7620dc969a2eb707f0c864145 (diff) | |
download | ATCD-1b1499ded161f2ed308908bcfd48d97e2fa4424c.tar.gz |
ChangeLogTag: Wed Sep 5 12:10:40 2001 Priyanka Gontla <gontla_p@ociweb.com>
-rw-r--r-- | TAO/ChangeLogs/ChangeLog-02a | 50 | ||||
-rw-r--r-- | TAO/tao/MCAST_Parser.cpp | 418 | ||||
-rw-r--r-- | TAO/tao/MCAST_Parser.h | 97 | ||||
-rw-r--r-- | TAO/tao/MCAST_Parser.i | 6 | ||||
-rw-r--r-- | TAO/tao/Makefile | 2 | ||||
-rw-r--r-- | TAO/tao/ORB.cpp | 293 | ||||
-rw-r--r-- | TAO/tao/ORB.h | 17 | ||||
-rw-r--r-- | TAO/tao/ORB_Core.cpp | 12 | ||||
-rw-r--r-- | TAO/tao/TAO_Internal.cpp | 6 | ||||
-rw-r--r-- | TAO/tao/default_resource.cpp | 25 |
10 files changed, 617 insertions, 309 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a index 4b465ad27f3..467bf0283db 100644 --- a/TAO/ChangeLogs/ChangeLog-02a +++ b/TAO/ChangeLogs/ChangeLog-02a @@ -1,3 +1,53 @@ +Wed Sep 5 12:10:40 2001 Priyanka Gontla <gontla_p@ociweb.com> + + This set of changes are for bug 977. + + * tao/MCAST_Parser.i: + * tao/MCAST_Parser.h: + * tao/MCAST_Parser.cpp: + + The Parser for the new IP multicast format. The multicast + format is mcast://mcast_address:mcast_port:nic_address:ttl. + All the multicast requests are now dealt via this parser. The default + multicast address is 224.9.9.2. The default multicast port is + 10013 ( the same port that we used for NameService .. no big + reason .. just a simple choice), default nic is eth0 and default + TTL value is 1. + + * tao/TAO_Internal.cpp: + Add MCAST protocol to the list of services that have to be + initiated. + + * tao/ORB.h : + * tao/ORB.cpp : + Moved the multicast_to_service and multicast_query methods to + MCAST_Parser. Modified ::resolve_service accordingly. + + * tao/ORB_Core.cpp : + Check for mcast: format when ORBDefaultInitRef option is used + and set the object delimiter to '/' if it is mcast protocol. + + * tao/default_resource.cpp: + Modify the total no. of parsers to check for: from 4 to 5. + and dynamically load the MCAST_Parser too. + + * tao/Makefile: + Added MCAST_Parser + + * orbsvcs/tests/IOR_MCast/README : + * orbsvcs/tests/IOR_MCast/Makefile : + * orbsvcs/tests/IOR_MCast/MCast.idl : + * orbsvcs/tests/IOR_MCast/MCast_Server_i.h : + * orbsvcs/tests/IOR_MCast/MCast_Server_i.cpp : + * orbsvcs/tests/IOR_MCast/client.cpp : + * orbsvcs/tests/IOR_MCast/ior_mcast_client_i.h : + * orbsvcs/tests/IOR_MCast/ior_mcast_client_i.cpp : + * orbsvcs/tests/IOR_MCast/server.cpp : + * orbsvcs/tests/IOR_MCast/server_i.h : + * orbsvcs/tests/IOR_MCast/server_i.cpp : + + Simple test to test the new MCAST_Parser. + Wed Sep 5 12:35:33 2001 Balachandran Natarajan <bala@cs.wustl.edu> * tao/Endpoint.h: Added a lock that is used to lock when a thread diff --git a/TAO/tao/MCAST_Parser.cpp b/TAO/tao/MCAST_Parser.cpp new file mode 100644 index 00000000000..75d83bbb265 --- /dev/null +++ b/TAO/tao/MCAST_Parser.cpp @@ -0,0 +1,418 @@ +// $Id$ + +#include "MCAST_Parser.h" +#include "tao/Object_Loader.h" +#include "tao/Object.h" +#include "tao/ORB.h" +#include "tao/Exception.h" +#include "tao/Environment.h" +#include "ace/Read_Buffer.h" +#include "ace/INET_Addr.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/SOCK_Dgram.h" +#include "ace/SOCK_Stream.h" + +#if !defined(__ACE_INLINE__) +#include "MCAST_Parser.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(tao, MCAST_Parser, "$Id$") + +TAO_MCAST_Parser::~TAO_MCAST_Parser (void) +{ +} + +static const char mcast_prefix[] = "mcast:"; + +int +TAO_MCAST_Parser::match_prefix (const char *ior_string) const +{ + return (ACE_OS::strncmp (ior_string, + ::mcast_prefix, + sizeof (::mcast_prefix) - 1) == 0); +} + +CORBA::Object_ptr +TAO_MCAST_Parser::parse_string (const char *ior, + CORBA::ORB_ptr orb, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + const char *mcast_name = + ior + sizeof (::mcast_prefix) + 1; + + assign_to_variables (mcast_name); + + /* + * Now that we got the global variables. + * we can invoke multicast_to_service and multicast_query + */ + CORBA::Object_ptr object = CORBA::Object::_nil (); + + CORBA::UShort port = (CORBA::UShort) ACE_OS::atoi (this->mcast_port_.in + ()); + + ACE_Time_Value *timeout = 0; + object = multicast_to_service (service_name_.in (), + port, + this->mcast_address_.in (), + this->mcast_ttl_.in (), + this->mcast_nic_.in (), + orb, + timeout, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + return object; +} + +CORBA_Object_ptr +TAO_MCAST_Parser::multicast_to_service (const char *service_name, + u_short port, + const char *mcast_address, + const char *mcast_ttl, + const char *mcast_nic, + CORBA::ORB_ptr orb, + ACE_Time_Value *timeout, + CORBA::Environment& ACE_TRY_ENV) +{ + char buf[2048]; + char *ior = buf; + + CORBA::String_var cleaner; + + CORBA_Object_var return_value = + CORBA_Object::_nil (); + + // Use UDP multicast to locate the service. + int result = this->multicast_query (ior, + service_name, + port, + mcast_address, + mcast_ttl, + mcast_nic, + timeout, + orb); + + // If the IOR didn't fit into <buf>, memory for it was dynamically + // allocated - make sure it gets deallocated. + if (ior != buf) + cleaner = ior; + + if (result == 0) + { + // Convert IOR to an object reference. + return_value = + orb->string_to_object (ior, + ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA_Object::_nil ()); + } + + // Return object reference. + return return_value._retn (); +} + +int +TAO_MCAST_Parser::multicast_query (char *&buf, + const char *service_name, + u_short port, + const char *mcast_address, + const char *mcast_ttl, + const char *mcast_nic, + ACE_Time_Value *timeout, + CORBA::ORB_ptr orb) +{ + ACE_INET_Addr my_addr; + ACE_SOCK_Acceptor acceptor; + ACE_SOCK_Stream stream; + ACE_SOCK_Dgram dgram; + + ssize_t result = 0; + + // Bind listener to any port and then find out what the port was. + if (acceptor.open (ACE_Addr::sap_any) == -1 + || acceptor.get_local_addr (my_addr) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("acceptor.open () || ") + ACE_TEXT ("acceptor.get_local_addr () failed"))); + result = -1; + } + else + { + ACE_INET_Addr multicast_addr (port, + mcast_address); + + // Set the address if multicast_discovery_endpoint option + // is specified for the Naming Service. + ACE_CString mde (orb->orb_core ()->orb_params () + ->mcast_discovery_endpoint ()); + + if (ACE_OS::strcasecmp (service_name, + "NameService") == 0 + && mde.length () != 0) + if (multicast_addr.set (mde.c_str()) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT("ORB.cpp: Multicast address setting failed\n"))); + stream.close (); + dgram.close (); + acceptor.close (); + return -1; + } + + // Open the datagram. + if (dgram.open (ACE_Addr::sap_any) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Unable to open the Datagram!\n"))); + result = -1; + } + else + { + // Set NIC + dgram.set_nic (mcast_nic); + + //Set TTL + dgram.ACE_SOCK::set_option (IPPROTO_IP, + IP_MULTICAST_TTL, + ACE_reinterpret_cast (void *, + ACE_const_cast + (char *, + mcast_ttl)), + sizeof (mcast_ttl)); + + // Convert the acceptor port into network byte order. + ACE_UINT16 response_port = + (ACE_UINT16) ACE_HTONS (my_addr.get_port_number ()); + + // Length of service name we will send. + CORBA::Short data_len = + (CORBA::Short) ACE_HTONS (ACE_OS::strlen (service_name) + 1); + + // Vector we will send. It contains: 1) length of service + // name string, 2)port on which we are listening for + // replies, and 3) name of service we are looking for. + const int iovcnt = 3; + iovec iovp[iovcnt]; + + // The length of service name string. + iovp[0].iov_base = (char *) &data_len; + iovp[0].iov_len = sizeof (CORBA::Short); + + // The port at which we are listening. + iovp[1].iov_base = (char *) &response_port; + iovp[1].iov_len = sizeof (ACE_UINT16); + + // The service name string. + iovp[2].iov_base = (char *) service_name; + iovp[2].iov_len = ACE_OS::strlen (service_name) + 1; + + // Send the multicast. + result = dgram.send (iovp, + iovcnt, + multicast_addr); + + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\nsent multicast request."))); + + // Check for errors. + if (result == -1) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("error sending IIOP multicast"))); + else + { + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\n%s; Sent multicast.") + ACE_TEXT ("# of bytes sent is %d.\n"), + __FILE__, + result)); + // Wait for response until timeout. + ACE_Time_Value tv ( + timeout == 0 + ? ACE_Time_Value (TAO_DEFAULT_SERVICE_RESOLUTION_TIMEOUT) + : *timeout); + + // Accept reply connection from server. + if (acceptor.accept (stream, + 0, + &tv) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("multicast_query: unable to accept"))); + result = -1; + } + else + { + // Receive the IOR. + + // IOR length. + CORBA::Short ior_len; + result = stream.recv_n (&ior_len, + sizeof ior_len, + 0, + &tv); + if (result != sizeof (ior_len)) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("multicast_query: unable to receive ") + ACE_TEXT ("ior length"))); + result = -1; + } + else + { + // Allocate more space for the ior if we don't + // have enough. + ior_len = (CORBA::Short) ACE_NTOHS (ior_len); + if (ior_len > TAO_DEFAULT_IOR_SIZE) + { + buf = CORBA::string_alloc (ior_len); + if (buf == 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("multicast_query: unable to ") + ACE_TEXT ("allocate memory"))); + result = -1; + } + } + + if (result != -1) + { + // Receive the ior. + result = stream.recv_n (buf, + ior_len, + 0, + &tv); + if (result == -1) + ACE_ERROR ((LM_ERROR, + ACE_TEXT ( "%p\n"), + ACE_TEXT ("error reading ior"))); + else if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%s: service resolved to IOR <%s>\n"), + __FILE__, + buf)); + } + } + } + } + } + } + + // Clean up. + stream.close (); + dgram.close (); + acceptor.close (); + + return result == -1 ? -1 : 0; +} + +void +TAO_MCAST_Parser::assign_to_variables (const char * &mcast_name) +{ + /* + * The format now is "multicast_address:port:nicaddress:ttl/object_key" + */ + ACE_CString mcast_name_cstring (mcast_name); + + int pos_colon1 = mcast_name_cstring.find (':', 0); + + if (pos_colon1 == 0) + { + this->mcast_address_ = ACE_DEFAULT_MULTICAST_ADDR; + } + else + this->mcast_address_ = mcast_name_cstring.substring (0, + pos_colon1).c_str (); + + mcast_name_cstring = + mcast_name_cstring.substring (pos_colon1 + 1, + mcast_name_cstring.length() - + pos_colon1); + + int pos_colon2 = mcast_name_cstring.find (':', 0); + + if (pos_colon2 == 0) + { + /* + * If the port is not specified, use the default. + * The default multicast port is the same as the default port + * no. for Naming_Service, for now. + */ + char trial_port[33]; + + ACE_OS_String::itoa (TAO_DEFAULT_NAME_SERVER_REQUEST_PORT, + trial_port, + 10); + + this->mcast_port_ = (const char *) trial_port; + } + else + { + this->mcast_port_ = mcast_name_cstring.substring (0, + pos_colon2).c_str (); + } + + mcast_name_cstring = + mcast_name_cstring.substring (pos_colon2 + 1, + mcast_name_cstring.length() - pos_colon2); + + int pos_colon3 = mcast_name_cstring.find (':', 0); + + if (pos_colon3 == 0) + { + // The default NIC to be eth0. + this->mcast_nic_ = "eth0"; + } + else + this->mcast_nic_ = + mcast_name_cstring.substring (0, + pos_colon3).c_str (); + + mcast_name_cstring = + mcast_name_cstring.substring (pos_colon3 + 1, + mcast_name_cstring.length() - pos_colon3); + + int pos_colon4 = mcast_name_cstring.find ('/', 0); + + if (pos_colon4 == 0) + { + // And, the default TTL to be 1. + this->mcast_ttl_ = "1"; + } + else + this->mcast_ttl_ = + mcast_name_cstring.substring (0, + pos_colon4).c_str (); + + mcast_name_cstring = + mcast_name_cstring.substring (pos_colon4, + mcast_name_cstring.length() - pos_colon4); + + this->service_name_ = + mcast_name_cstring.substring (1, + mcast_name_cstring.length() + -1).c_str (); +} + +ACE_STATIC_SVC_DEFINE (TAO_MCAST_Parser, + ACE_TEXT ("MCAST_Parser"), + ACE_SVC_OBJ_T, + &ACE_SVC_NAME (TAO_MCAST_Parser), + ACE_Service_Type::DELETE_THIS | + ACE_Service_Type::DELETE_OBJ, + 0) + +ACE_FACTORY_DEFINE (TAO, TAO_MCAST_Parser) + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/MCAST_Parser.h b/TAO/tao/MCAST_Parser.h new file mode 100644 index 00000000000..66a18c5943e --- /dev/null +++ b/TAO/tao/MCAST_Parser.h @@ -0,0 +1,97 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file MCAST_Parser.h + * + * $Id$ + * + * @author Priyanka Gontla (gontla_p@ociweb.com) + */ +//============================================================================= + + +#ifndef TAO_MCAST_PARSER_H +#define TAO_MCAST_PARSER_H +#include "ace/pre.h" + +#include "tao/IOR_Parser.h" +#include "tao/ORB_Core.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Config.h" +#include "ace/OS.h" + +/** + * @class TAO_MCAST_Parser + * + * @brief Implements the <mcast:> IOR format + * + * This class implements the <mcast:> IOR format. + * It is dynamically loaded by the ORB and used to parse the + * string to separate the individual <obj_addr> from the list of object + * addresses <obj_addr_list>. + */ +class TAO_Export TAO_MCAST_Parser : public TAO_IOR_Parser +{ +public: + /// Constructor + TAO_MCAST_Parser (void); + + /// The destructor + virtual ~TAO_MCAST_Parser (void); + + /// = The IOR_Parser methods, please read the documentation in + /// IOR_Parser.h + virtual int match_prefix (const char *ior_string) const; + + /// Parse the ior-string that is passed. + virtual CORBA::Object_ptr parse_string (const char *ior, + CORBA::ORB_ptr orb, + CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + + CORBA_Object_ptr multicast_to_service (const char *service_name, + CORBA::UShort port, + const char *mcast_address, + const char *mcast_ttl, + const char *mcast_nic, + CORBA::ORB_ptr orb, + ACE_Time_Value *timeout, + CORBA::Environment&); + + int multicast_query (char *&buf, + const char *service_name, + u_short port, + const char *mcast_address, + const char *mcast_ttl, + const char *mcast_nic, + ACE_Time_Value *timeout, + CORBA::ORB_ptr orb); + + /* Simple method to assign values to the global members: + mcast_address_, mcast_port_, mcast_nic_, mcast_ttl_ */ + void assign_to_variables (const char * &mcast_name_ptr); + + // Global private variables + CORBA::String_var mcast_address_; + CORBA::String_var mcast_port_; + CORBA::String_var mcast_nic_; + CORBA::String_var mcast_ttl_; + CORBA::String_var service_name_; +}; + +#if defined (__ACE_INLINE__) +# include "MCAST_Parser.i" +#endif /* __ACE_INLINE__ */ + +ACE_STATIC_SVC_DECLARE_EXPORT (TAO, TAO_MCAST_Parser) +ACE_FACTORY_DECLARE (TAO, TAO_MCAST_Parser) + +#include "ace/post.h" +#endif /* TAO_MCAST_PARSER_H */ diff --git a/TAO/tao/MCAST_Parser.i b/TAO/tao/MCAST_Parser.i new file mode 100644 index 00000000000..c2a5c736f82 --- /dev/null +++ b/TAO/tao/MCAST_Parser.i @@ -0,0 +1,6 @@ +// $Id$ + +ACE_INLINE +TAO_MCAST_Parser::TAO_MCAST_Parser (void) +{ +} diff --git a/TAO/tao/Makefile b/TAO/tao/Makefile index 8c5712e20b1..9acac0c2a09 100644 --- a/TAO/tao/Makefile +++ b/TAO/tao/Makefile @@ -86,6 +86,7 @@ PUB_HDRS = \ FILE_Parser \ CORBALOC_Parser \ CORBANAME_Parser \ + MCAST_Parser \ CORBA_String \ Connection_Purging_Strategy \ LRU_Connection_Purging_Strategy @@ -245,6 +246,7 @@ ORB_CORE_FILES = \ FILE_Parser \ CORBALOC_Parser \ CORBANAME_Parser \ + MCAST_Parser \ Bind_Dispatcher_Guard \ Fault_Tolerance_Service \ Interceptor_List \ diff --git a/TAO/tao/ORB.cpp b/TAO/tao/ORB.cpp index 200f90dee9d..851c234ae85 100644 --- a/TAO/tao/ORB.cpp +++ b/TAO/tao/ORB.cpp @@ -54,7 +54,7 @@ # if defined (ACE_HAS_STANDARD_CPP_LIBRARY) # include /**/ <exception> # if !defined (_MSC_VER) && defined (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB) && \ - (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0) + (ACE_USES_STD_NAMESPACE_FOR_STDCPP_LIB != 0) using std::set_unexpected; # endif /* !_MSC_VER */ # else @@ -959,30 +959,6 @@ CORBA_ORB::resolve_service (MCAST_SERVICEID mcast_service_id, "InterfaceRepoServiceIOR" }; - const char * env_service_port [] = - { - "NameServicePort", - "TradingServicePort", - "ImplRepoServicePort", - "InterfaceRepoServicePort" - }; - - u_short default_service_port [] = - { - TAO_DEFAULT_NAME_SERVER_REQUEST_PORT, - TAO_DEFAULT_TRADING_SERVER_REQUEST_PORT, - TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT, - TAO_DEFAULT_INTERFACEREPO_SERVER_REQUEST_PORT - }; - - const char * service_objid [] = - { - TAO_OBJID_NAMESERVICE, - TAO_OBJID_TRADINGSERVICE, - TAO_OBJID_IMPLREPOSERVICE, - TAO_OBJID_INTERFACEREP - }; - CORBA_Object_var return_value = CORBA_Object::_nil (); // By now, the table filled in with -ORBInitRef arguments has been @@ -992,271 +968,15 @@ CORBA_ORB::resolve_service (MCAST_SERVICEID mcast_service_id, // Check to see if the user has an environment variable. ACE_CString service_ior = ACE_OS::getenv (env_service_ior[mcast_service_id]); - if (service_ior.length () != 0) - { - return_value = - this->string_to_object (service_ior.c_str (), - ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA_Object::_nil ()); - } - else - { - // First, determine if the port was supplied on the command line - u_short port = - this->orb_core_->orb_params ()->service_port (mcast_service_id); - - if (port == 0) - { - // Look for the port among our environment variables. - const char *port_number = - ACE_OS::getenv (env_service_port[mcast_service_id]); - - if (port_number != 0) - port = (u_short) ACE_OS::atoi (port_number); - else - port = default_service_port[mcast_service_id]; - } - - return_value = - this->multicast_to_service (service_objid[mcast_service_id], - port, - timeout, - ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA_Object::_nil ()); - } - + return_value = + this->string_to_object (service_ior.c_str (), + ACE_TRY_ENV); + ACE_CHECK_RETURN (CORBA_Object::_nil ()); + // Return ior. return return_value._retn (); } -int -CORBA_ORB::multicast_query (char *&buf, - const char *service_name, - u_short port, - ACE_Time_Value *timeout) -{ - ACE_INET_Addr my_addr; - ACE_SOCK_Acceptor acceptor; - ACE_SOCK_Stream stream; - ACE_SOCK_Dgram dgram; - - ssize_t result = 0; - - // Bind listener to any port and then find out what the port was. - if (acceptor.open (ACE_Addr::sap_any) == -1 - || acceptor.get_local_addr (my_addr) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("acceptor.open () || ") - ACE_TEXT ("acceptor.get_local_addr () failed"))); - result = -1; - } - else - { - ACE_INET_Addr multicast_addr (port, - ACE_DEFAULT_MULTICAST_ADDR); - // Set the address if multicast_discovery_endpoint option - // is specified for the Naming Service. - ACE_CString mde (this->orb_core_->orb_params () - ->mcast_discovery_endpoint ()); - - if (ACE_OS::strcasecmp (service_name, - "NameService") == 0 - && mde.length () != 0) - if (multicast_addr.set (mde.c_str()) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT("ORB.cpp: Multicast address setting failed\n"))); - stream.close (); - dgram.close (); - acceptor.close (); - return -1; - } - - // Open the datagram. - if (dgram.open (ACE_Addr::sap_any) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("Unable to open the Datagram!\n"))); - result = -1; - } - else - { - // Convert the acceptor port into network byte order. - ACE_UINT16 response_port = - (ACE_UINT16) ACE_HTONS (my_addr.get_port_number ()); - - // Length of service name we will send. - CORBA::Short data_len = - (CORBA::Short) ACE_HTONS (ACE_OS::strlen (service_name) + 1); - - // Vector we will send. It contains: 1) length of service - // name string, 2)port on which we are listening for - // replies, and 3) name of service we are looking for. - const int iovcnt = 3; - iovec iovp[iovcnt]; - - // The length of service name string. - iovp[0].iov_base = (char *) &data_len; - iovp[0].iov_len = sizeof (CORBA::Short); - - // The port at which we are listening. - iovp[1].iov_base = (char *) &response_port; - iovp[1].iov_len = sizeof (ACE_UINT16); - - // The service name string. - iovp[2].iov_base = (char *) service_name; - iovp[2].iov_len = ACE_OS::strlen (service_name) + 1; - - // Send the multicast. - result = dgram.send (iovp, - iovcnt, - multicast_addr); - - if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("\nsent multicast request."))); - - // Check for errors. - if (result == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("error sending IIOP multicast"))); - else - { - if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("\n%s; Sent multicast.") - ACE_TEXT ("# of bytes sent is %d.\n"), - __FILE__, - result)); - // Wait for response until timeout. - ACE_Time_Value tv ( - timeout == 0 - ? ACE_Time_Value (TAO_DEFAULT_SERVICE_RESOLUTION_TIMEOUT) - : *timeout); - - // Accept reply connection from server. - if (acceptor.accept (stream, - 0, - &tv) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("multicast_query: unable to accept"))); - result = -1; - } - else - { - // Receive the IOR. - - // IOR length. - CORBA::Short ior_len; - result = stream.recv_n (&ior_len, - sizeof ior_len, - 0, - &tv); - if (result != sizeof (ior_len)) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("multicast_query: unable to receive ") - ACE_TEXT ("ior length"))); - result = -1; - } - else - { - // Allocate more space for the ior if we don't - // have enough. - ior_len = (CORBA::Short) ACE_NTOHS (ior_len); - if (ior_len > TAO_DEFAULT_IOR_SIZE) - { - buf = CORBA::string_alloc (ior_len); - if (buf == 0) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("multicast_query: unable to ") - ACE_TEXT ("allocate memory"))); - result = -1; - } - } - - if (result != -1) - { - // Receive the ior. - result = stream.recv_n (buf, - ior_len, - 0, - &tv); - if (result == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ( "%p\n"), - ACE_TEXT ("error reading ior"))); - else if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("%s: service resolved to IOR <%s>\n"), - __FILE__, - buf)); - } - } - } - } - } - } - - // Clean up. - stream.close (); - dgram.close (); - acceptor.close (); - - return result == -1 ? -1 : 0; -} -// @@ This will have to be sanitized of transport specific calls -// in order to support pluggable protocols! But, it does use -// UDP and multicast. Not all transport protocols may support -// this, connectionless and multicast. fredk - // @@ FRED: Should define a flag, something like Protocol_Has_Multicast -// If there is no multicast, then this functionality is not available -// and we return NULL. - -CORBA_Object_ptr -CORBA_ORB::multicast_to_service (const char *service_name, - u_short port, - ACE_Time_Value *timeout, - CORBA::Environment& ACE_TRY_ENV) -{ - char buf[TAO_DEFAULT_IOR_SIZE]; - char *ior = buf; - CORBA::String_var cleaner; - - CORBA_Object_var return_value = - CORBA_Object::_nil (); - - // Use UDP multicast to locate the service. - int result = this->multicast_query (ior, - service_name, - port, - timeout); - - // If the IOR didn't fit into <buf>, memory for it was dynamically - // allocated - make sure it gets deallocated. - if (ior != buf) - cleaner = ior; - - if (result == 0) - { - // Convert IOR to an object reference. - return_value = - this->string_to_object (ior, - ACE_TRY_ENV); - ACE_CHECK_RETURN (CORBA_Object::_nil ()); - } - - // Return object reference. - return return_value._retn (); -} - CORBA_Object_ptr CORBA_ORB::resolve_initial_references (const char *name, CORBA_Environment &ACE_TRY_ENV) @@ -1544,6 +1264,7 @@ CORBA::ORB_init (int &argc, const char *orbid, CORBA_Environment &ACE_TRY_ENV) { + // Using ACE_Static_Object_Lock::instance() precludes <ORB_init> // from being called within a static object CTOR. ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, guard, diff --git a/TAO/tao/ORB.h b/TAO/tao/ORB.h index 34cc99d792c..953ce94aca5 100644 --- a/TAO/tao/ORB.h +++ b/TAO/tao/ORB.h @@ -36,7 +36,8 @@ typedef enum TAO_SERVICEID_NAMESERVICE, TAO_SERVICEID_TRADINGSERVICE, TAO_SERVICEID_IMPLREPOSERVICE, - TAO_SERVICEID_INTERFACEREPOSERVICE + TAO_SERVICEID_INTERFACEREPOSERVICE, + TAO_SERVICEID_MCASTSERVER } TAO_Service_ID; /// Forward declarations. @@ -552,20 +553,6 @@ private: ACE_Time_Value *timeout, CORBA::Environment& ACE_TRY_ENV); - int multicast_query (char* &buf, - const char *service_name, - u_short port, - ACE_Time_Value *timeout); - - // returns and IOR string, the client is responsible for freeing - // memory! - - /// Resolve the reference of a service of type <name>. - CORBA_Object_ptr multicast_to_service (const char *service_name, - u_short port, - ACE_Time_Value *timeout, - CORBA::Environment& ACE_TRY_ENV); - /// Convert an OMG IOR into an object reference. CORBA::Object_ptr ior_string_to_object (const char* ior, CORBA::Environment &ACE_TRY_ENV); diff --git a/TAO/tao/ORB_Core.cpp b/TAO/tao/ORB_Core.cpp index 38e20e95b8e..ce69d6c6a29 100644 --- a/TAO/tao/ORB_Core.cpp +++ b/TAO/tao/ORB_Core.cpp @@ -2407,15 +2407,19 @@ TAO_ORB_Core::resolve_rir (const char *name, if (ACE_OS::strlen (default_init_ref.in ()) != 0) { static const char corbaloc_prefix[] = "corbaloc:"; + static const char mcast_prefix[] = "mcast:"; char object_key_delimiter = 0; ACE_CString list_of_profiles (default_init_ref.in ()); - // Check if the protocol is corbaloc:. + // Check if the protocol is corbaloc: or mcast:. // If it is, set the object_key_delimiter. - if (ACE_OS::strncmp (default_init_ref.in (), - corbaloc_prefix, - sizeof corbaloc_prefix -1) == 0) + if ((ACE_OS::strncmp (default_init_ref.in (), + corbaloc_prefix, + sizeof corbaloc_prefix -1) == 0) || + (ACE_OS::strncmp (default_init_ref.in (), + mcast_prefix, + sizeof mcast_prefix -1) == 0)) { object_key_delimiter = '/'; } diff --git a/TAO/tao/TAO_Internal.cpp b/TAO/tao/TAO_Internal.cpp index b65a7280a39..bac2f70fb8c 100644 --- a/TAO/tao/TAO_Internal.cpp +++ b/TAO/tao/TAO_Internal.cpp @@ -11,7 +11,7 @@ #include "default_resource.h" #include "IIOP_Factory.h" - +#include "MCAST_Parser.h" #include "CORBANAME_Parser.h" #include "CORBALOC_Parser.h" #include "FILE_Parser.h" @@ -212,6 +212,8 @@ TAO_Internal::open_services_i (int &argc, insert (&ace_svc_desc_TAO_IIOP_Protocol_Factory); // add descriptor to list of static objects. ACE_Service_Config::static_svcs ()-> + insert (&ace_svc_desc_TAO_MCAST_Parser); + ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_CORBANAME_Parser); ACE_Service_Config::static_svcs ()-> insert (&ace_svc_desc_TAO_CORBALOC_Parser); @@ -239,7 +241,7 @@ TAO_Internal::open_services_i (int &argc, // Handle RTCORBA library special case. Since RTCORBA needs // its init method call to register several hooks, call it here // if it hasn't already been called. - TAO_Object_Loader *rt_loader = + TAO_Object_Loader *rt_loader = ACE_Dynamic_Service<TAO_Object_Loader>::instance ("RT_ORB_Loader"); if (rt_loader != 0) rt_loader->init (0, 0); diff --git a/TAO/tao/default_resource.cpp b/TAO/tao/default_resource.cpp index 81773712f28..d8862d89761 100644 --- a/TAO/tao/default_resource.cpp +++ b/TAO/tao/default_resource.cpp @@ -386,7 +386,7 @@ TAO_Default_Resource_Factory::get_parser_names (char **&names, } // OK fallback on the hardcoded ones.... - this->parser_names_count_ = 4; // HOW MANY DO WE HAVE? + this->parser_names_count_ = 5; // HOW MANY DO WE HAVE? this->parser_names_ = new char *[this->parser_names_count_]; @@ -479,7 +479,28 @@ TAO_Default_Resource_Factory::get_parser_names (char **&names, } } - this->parser_names_[index] = CORBA::string_dup ("CORBANAME_Parser"); + this->parser_names_[index] = CORBA::string_dup ("CORBALOC_Parser"); + index++; + + // MCAST_Parser + tmp = + ACE_Dynamic_Service<TAO_IOR_Parser>::instance ("MCAST_Parser"); + + if (tmp == 0) + { + int r = ACE_Service_Config::process_directive + ( + "dynamic MCAST_Parser Service_Object * TAO :_make_TAO_MCAST_Parser()" + ); + + if (r != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Error Configuring MCAST Parser\n"), -1); + } + } + + this->parser_names_[index] = CORBA::string_dup ("MCAST_Parser"); index++; names = this->parser_names_; |