Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Transport_Acceptor.cpp
blobbdf634c708b55ac6c596e3ec69714fa7665f5c7f
1 // -*- C++ -*-
2 #include "tao/Transport_Acceptor.h"
3 #include "ace/Reactor.h"
4 #include "tao/debug.h"
6 #if !defined (__ACE_INLINE__)
7 # include "tao/Transport_Acceptor.inl"
8 #endif /* __ACE_INLINE__ */
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 TAO_Acceptor::TAO_Acceptor (CORBA::ULong tag)
13 : tag_ (tag),
14 error_retry_delay_ (5)
18 TAO_Acceptor::~TAO_Acceptor ()
22 int
23 TAO_Acceptor::handle_accept_error (ACE_Event_Handler* base_acceptor)
25 if (errno == EMFILE || errno == ENFILE)
27 if (TAO_debug_level > 0)
28 TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - "
29 "TAO_Acceptor::handle_accept_error - "
30 "Too many files open\n"));
32 // If the user has decided to stop accepting when the file handles
33 // run out, just return -1;
34 if (this->error_retry_delay_ == 0)
35 return -1;
37 // Get the reactor. If there isn't one, which isn't very likely,
38 // then just return -1.
39 ACE_Reactor* reactor = base_acceptor->reactor ();
40 if (reactor == nullptr)
41 return -1;
43 // So that the reactor doesn't completely remove this handler from
44 // the reactor, register it with the except mask. It should be
45 // removed in the timer handler.
46 reactor->register_handler (base_acceptor,
47 ACE_Event_Handler::EXCEPT_MASK);
49 // Remove the handler so that the reactor doesn't attempt to
50 // process this handle again (and tightly spin).
51 reactor->remove_handler (base_acceptor,
52 ACE_Event_Handler::ACCEPT_MASK |
53 ACE_Event_Handler::DONT_CALL);
55 // Schedule a timer so that we can resume the handler in hopes
56 // that some file handles have freed up.
57 ACE_Time_Value timeout (this->error_retry_delay_);
58 reactor->schedule_timer (base_acceptor, nullptr, timeout);
61 // We want to keep accepting in all other situations.
62 return 0;
65 int
66 TAO_Acceptor::handle_expiration (ACE_Event_Handler* base_acceptor)
68 // Get the reactor. If there isn't one, which isn't very likely, then
69 // just return -1;
70 ACE_Reactor* reactor = base_acceptor->reactor ();
71 if (reactor == nullptr)
72 return -1;
74 if (TAO_debug_level > 0)
75 TAOLIB_DEBUG ((LM_DEBUG, "TAO (%P|%t) - "
76 "TAO_Acceptor::handle_expiration - "
77 "Re-registering the acceptor\n"));
79 // Try again to allow incoming connections
80 reactor->register_handler (base_acceptor, ACE_Event_Handler::ACCEPT_MASK);
82 // Remove the except mask that was added during the handling of the
83 // accept() error. That is the only reason that we're in this method
84 // in the first place.
85 reactor->remove_handler (base_acceptor, ACE_Event_Handler::EXCEPT_MASK |
86 ACE_Event_Handler::DONT_CALL);
87 return 0;
90 TAO_END_VERSIONED_NAMESPACE_DECL