Transport_Acceptor.cpp

Go to the documentation of this file.
00001 // $Id: Transport_Acceptor.cpp 81470 2008-04-28 12:40:23Z elliott_c $
00002 
00003 #include "tao/Transport_Acceptor.h"
00004 #include "ace/Reactor.h"
00005 #include "tao/debug.h"
00006 
00007 #if !defined (__ACE_INLINE__)
00008 # include "tao/Transport_Acceptor.inl"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 ACE_RCSID (tao,
00012            Acceptor,
00013            "$Id: Transport_Acceptor.cpp 81470 2008-04-28 12:40:23Z elliott_c $")
00014 
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 TAO_Acceptor::TAO_Acceptor (CORBA::ULong tag)
00019   : tag_ (tag),
00020     error_retry_delay_ (5)
00021 {
00022 }
00023 
00024 TAO_Acceptor::~TAO_Acceptor (void)
00025 {
00026 
00027   //@@ TAO_ACCEPTOR_DESTRUCTOR_ADD_HOOK
00028 }
00029 
00030 int
00031 TAO_Acceptor::handle_accept_error (ACE_Event_Handler* base_acceptor)
00032 {
00033   if (errno == EMFILE || errno == ENFILE)
00034     {
00035       if (TAO_debug_level > 0)
00036         ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - "
00037                               "TAO_Acceptor::handle_accept_error - "
00038                               "Too many files open\n"));
00039 
00040       // If the user has decided to stop accepting when the file handles
00041       // run out, just return -1;
00042       if (this->error_retry_delay_ == 0)
00043         return -1;
00044 
00045       // Get the reactor.  If there isn't one, which isn't very likely,
00046       // then just return -1.
00047       ACE_Reactor* reactor = base_acceptor->reactor ();
00048       if (reactor == 0)
00049         return -1;
00050 
00051       // So that the reactor doesn't completely remove this handler from
00052       // the reactor, register it with the except mask.  It should be
00053       // removed in the timer handler.
00054       reactor->register_handler (base_acceptor,
00055                                  ACE_Event_Handler::EXCEPT_MASK);
00056 
00057       // Remove the handler so that the reactor doesn't attempt to
00058       // process this handle again (and tightly spin).
00059       reactor->remove_handler (base_acceptor,
00060                                ACE_Event_Handler::ACCEPT_MASK |
00061                                ACE_Event_Handler::DONT_CALL);
00062 
00063       // Schedule a timer so that we can resume the handler in hopes
00064       // that some file handles have freed up.
00065       ACE_Time_Value timeout (this->error_retry_delay_);
00066       reactor->schedule_timer (base_acceptor, 0, timeout);
00067     }
00068 
00069   // We want to keep accepting in all other situations.
00070   return 0;
00071 }
00072 
00073 int
00074 TAO_Acceptor::handle_expiration (ACE_Event_Handler* base_acceptor)
00075 {
00076   // Get the reactor.  If there isn't one, which isn't very likely, then
00077   // just return -1;
00078   ACE_Reactor* reactor = base_acceptor->reactor ();
00079   if (reactor == 0)
00080     return -1;
00081 
00082   if (TAO_debug_level > 0)
00083     ACE_DEBUG ((LM_DEBUG, "TAO (%P|%t) - "
00084                           "TAO_Acceptor::handle_expiration - "
00085                           "Re-registering the acceptor\n"));
00086 
00087   // Try again to allow incoming connections
00088   reactor->register_handler (base_acceptor, ACE_Event_Handler::ACCEPT_MASK);
00089 
00090   // Remove the except mask that was added during the handling of the
00091   // accept() error.  That is the only reason that we're in this method
00092   // in the first place.
00093   reactor->remove_handler (base_acceptor, ACE_Event_Handler::EXCEPT_MASK |
00094                                           ACE_Event_Handler::DONT_CALL);
00095   return 0;
00096 }
00097 
00098 //@@ TAO_ACCEPTOR_SPL_METHODS_ADD_HOOK
00099 
00100 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:37:53 2010 for TAO by  doxygen 1.4.7