From 23e62f52f46ea745b642b0d7010ac33d1d74f1b0 Mon Sep 17 00:00:00 2001 From: kirthika Date: Mon, 19 Jul 1999 22:51:41 +0000 Subject: Added TAO_Accept_Strategy --- TAO/tao/Acceptor_Impl.cpp | 139 +++++++++++++++++++++++++++++++++++++--------- TAO/tao/Acceptor_Impl.h | 107 +++++++++++++++++++++++------------ TAO/tao/Acceptor_Impl.i | 24 -------- 3 files changed, 186 insertions(+), 84 deletions(-) diff --git a/TAO/tao/Acceptor_Impl.cpp b/TAO/tao/Acceptor_Impl.cpp index f7d35cfaddd..bff63c918a2 100644 --- a/TAO/tao/Acceptor_Impl.cpp +++ b/TAO/tao/Acceptor_Impl.cpp @@ -26,6 +26,9 @@ #include "tao/ORB_Core.h" #include "tao/Server_Strategy_Factory.h" +#include "tao/IIOP_Connector.h" +#include "tao/UIOP_Connector.h" +#include "tao/Connector_Registry.h" #if !defined(__ACE_INLINE__) #include "tao/Acceptor_Impl.i" @@ -33,41 +36,38 @@ ACE_RCSID(tao, Acceptor_Impl, "$Id$") -template int -TAO_Acceptor_Impl::open (TAO_ORB_Core* orb_core, - const ACE_PEER_ACCEPTOR_ADDR &local_address, - int flags, - int use_select, - int reuse_addr) +template +TAO_Creation_Strategy::TAO_Creation_Strategy (TAO_ORB_Core *orb_core) + : orb_core_ (orb_core) { - this->orb_core_ = orb_core; - return this->ACE_Acceptor::open - (local_address, - this->orb_core_->reactor (), - flags, - use_select, - reuse_addr); } -template int -TAO_Acceptor_Impl::make_svc_handler (SVC_HANDLER *&sh) +template int +TAO_Creation_Strategy::make_svc_handler (SVC_HANDLER *&sh) { if (sh == 0) - { - if (this->orb_core_ == 0) - this->orb_core_ = TAO_ORB_Core_instance (); + ACE_NEW_RETURN (sh, + SVC_HANDLER (this->orb_core_), + -1); - ACE_NEW_RETURN (sh, - SVC_HANDLER (this->orb_core_), - -1); - } return 0; } -template int -TAO_Acceptor_Impl::activate_svc_handler (SVC_HANDLER *sh) +//--------------------------------------------------------------- + +template +TAO_Concurrency_Strategy::TAO_Concurrency_Strategy (TAO_ORB_Core *orb_core) + : orb_core_ (orb_core) { - if (this->ACE_Acceptor::activate_svc_handler (sh) == -1) +} + + +template int +TAO_Concurrency_Strategy::activate_svc_handler (SVC_HANDLER *sh, + void *arg) +{ + if (this->ACE_Concurrency_Strategy::activate_svc_handler (sh, + arg) == -1) return -1; TAO_Server_Strategy_Factory *f = @@ -77,8 +77,95 @@ TAO_Acceptor_Impl::activate_svc_handler (SVC_H return sh->activate (f->server_connection_thread_flags (), f->server_connection_thread_count ()); - return this->reactor ()->register_handler + return this->orb_core_->reactor ()->register_handler (sh, ACE_Event_Handler::READ_MASK); } +//--------------------------------------------------------------- + +template +TAO_Accept_Strategy::TAO_Accept_Strategy (TAO_ORB_Core *orb_core, + const CORBA::ULong &tag) + : ACE_Accept_Strategy (orb_core->reactor ()), + orb_core_ (orb_core), + tag_ (tag) +{ +} + +template int +TAO_Accept_Strategy::open (const ACE_PEER_ACCEPTOR_ADDR &local_addr, + int restart = 0) +{ + int result = ACCEPT_STRATEGY_BASE::open (local_addr, + restart); + + if (result == 0) + return result; + + // If the error occured due to the fact that the file descriptor + // limit was exhausted, then purge the connection cache of some + // entries. + result = this->out_of_sockets_handler (); + if (result == -1) + return -1; + + // If we are able to purge, try again. + return ACCEPT_STRATEGY_BASE::open (local_addr, restart); +} + +template int +TAO_Accept_Strategy::accept_svc_handler (SVC_HANDLER *svc_handler) +{ + // Try to find out if the implementation of the reactor that we are + // using requires us to reset the event association for the newly + // created handle. This is because the newly created handle will + // inherit the properties of the listen handle, including its event + // associations. + int reset_new_handle = this->orb_core_->reactor ()->uses_event_associations (); + + int result = this->acceptor_.accept (svc_handler->peer (), // stream + 0, // remote address + 0, // timeout + 1, // restart + reset_new_handle // reset new handler + ); + if (result == 0) + return result; + + // If the error occured due to the fact that the file descriptor + // limit was exhausted, then purge the connection cache of some + // entries. + result = this->out_of_sockets_handler (); + + // Note: SunOS5.5 as well as Linux crib when the accept is tried again after purging. + // Close down handler to avoid memory leaks. + svc_handler->close (0); + return -1; +} + +template TAO_PEER_CONNECTOR * +TAO_Accept_Strategy::get_connector (void) +{ + return ACE_dynamic_cast (TAO_PEER_CONNECTOR *, + this->orb_core_->connector_registry ()->get_connector (this->tag_)); + +} + +template int +TAO_Accept_Strategy::out_of_sockets_handler (void) +{ + // ENOBUFS had to be checked on NT while ENOENT check had to be + // added for Solaris + Linux. + if (ACE::out_of_handles (errno)) + { + // Close connections which are cached by explicitly purging the + // connection cache maintained by the connector. + ACE_DEBUG ((LM_DEBUG, "Purging connections from Connection Cache...\n")); + + return this->get_connector ()->cached_connect_strategy ().purge_connections (); + } + + return -1; +} + #endif /* TAO_ACCEPTOR_IMPL_C */ diff --git a/TAO/tao/Acceptor_Impl.h b/TAO/tao/Acceptor_Impl.h index de100f75f2d..596af1d36f4 100644 --- a/TAO/tao/Acceptor_Impl.h +++ b/TAO/tao/Acceptor_Impl.h @@ -24,51 +24,90 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -template class TAO_Acceptor_Impl : public ACE_Acceptor +// Forward declaration. +class TAO_IIOP_Connector; + +template +class TAO_Creation_Strategy : public ACE_Creation_Strategy { // = TITLE - // Helper class to implement the acceptors in TAO - // - // = DESCRIPTION - // TAO pluggable protocols framework provide an abstraction to - // represent any kind of acceptor object, the implementation of - // that acceptor is left for the pluggable protocol implementor, - // but the most common case would be to use an ACE_Acceptor<> - // instantiated over the right Svc_Handlers. - // But the Svc_Handlers must inherit the that owns the - // acceptor, though this could be implemented in each pluggable - // protocol we believe that this class would simplify that task - // and work in most cases. Pluggable protocol implementors are, - // of course, free to use something else. - // + // Creates a Svc_Handler and set the ORB_Core pointer on it. public: - // = Initialization and termination methods. - TAO_Acceptor_Impl (ACE_Reactor * = 0, - int use_select = 1); + TAO_Creation_Strategy (TAO_ORB_Core *orb_core); // Constructor. - TAO_Acceptor_Impl (const ACE_PEER_ACCEPTOR_ADDR &local_addr, - ACE_Reactor * = ACE_Reactor::instance (), - int flags = 0, - int use_select = 1, - int reuse_addr = 1); - // The constructors, just delegate to the base class. + int make_svc_handler (SVC_HANDLER *&sh); + // Create a SVC_HANDLER and set the ORB_Core pointer on it. + +protected: + TAO_ORB_Core *orb_core_; + // Pointer to the ORB Core. +}; + +template +class TAO_Concurrency_Strategy : public ACE_Concurrency_Strategy +{ + // = TITLE + // Activates the Svc_Handler, and then if specified by the + // TAO_Server_Strategy_Factory, it activates the Svc_Handler to + // run in its own thread. +public: + TAO_Concurrency_Strategy (TAO_ORB_Core *orb_core); + // Constructor. - int open (TAO_ORB_Core* orb_core, - const ACE_PEER_ACCEPTOR_ADDR &, - int flags = 0, - int use_select = 1, - int reuse_addr = 1); - // Initialize the ORB_Core. + int activate_svc_handler (SVC_HANDLER *svc_handler, + void *arg); + // Activates the Svc_Handler, and then if specified by the + // TAO_Server_Strategy_Factory, it activates the Svc_Handler to run + // in its own thread. protected: - // = See $ACE_ROOT/ace/Acceptor.h for the documentation. - virtual int make_svc_handler (SVC_HANDLER *&sh); - virtual int activate_svc_handler (SVC_HANDLER *svc_handler); + TAO_ORB_Core *orb_core_; + // Pointer to the ORB Core. +}; + +template +class TAO_Accept_Strategy : public ACE_Accept_Strategy +{ + // = TITLE + // This strategy tunes the acceptance of connections. When the + // process is out of descriptors needed to accept a connection, it + // requests the Connector to remove entries from its conenction + // cache. This is done based on the caching strategy specified at + // runtime. + +public: + + TAO_Accept_Strategy (TAO_ORB_Core *orb_core, + const CORBA::ULong &tag); + // Constructor. + + virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr, + int restart = 0); + // initialize acceptor for this address. + + virtual int accept_svc_handler (SVC_HANDLER *); + // The default behavior delegates to the method of the + // PEER_ACCEPTOR. + +protected: + + typedef ACE_Accept_Strategy ACCEPT_STRATEGY_BASE; + + TAO_PEER_CONNECTOR *get_connector (void); + // Obtain the connector needed for access to the connection strategy + // which removes entries from the connection cache on demand. + + int out_of_sockets_handler (void); + // Takes care when the process runs out of descriptors. private: + TAO_ORB_Core *orb_core_; - // Pointer to the ORB Core. + // ORB Core. + + CORBA::ULong tag_; + // The OMG specified tag for the concrete Acceptor. }; #if defined(__ACE_INLINE__) diff --git a/TAO/tao/Acceptor_Impl.i b/TAO/tao/Acceptor_Impl.i index 7cafd44c6d7..74e88caa0c5 100644 --- a/TAO/tao/Acceptor_Impl.i +++ b/TAO/tao/Acceptor_Impl.i @@ -1,26 +1,2 @@ // $Id$ -template ACE_INLINE -TAO_Acceptor_Impl:: - TAO_Acceptor_Impl (ACE_Reactor *reactor, - int use_select) - : ACE_Acceptor (reactor, use_select), - orb_core_ (0) -{ -} - -template ACE_INLINE -TAO_Acceptor_Impl:: - TAO_Acceptor_Impl (const ACE_PEER_ACCEPTOR_ADDR &local_addr, - ACE_Reactor * reactor, - int flags, - int use_select, - int reuse_addr) - : ACE_Acceptor (local_addr, - reactor, - flags, - use_select, - reuse_addr), - orb_core_ (0) -{ -} -- cgit v1.2.1