00001 // -*- C++ -*- 00002 // 00003 // $Id: Handle_Gobbler.inl 90388 2010-06-02 15:27:59Z vzykov $ 00004 00005 // Since this is only included in Handle_Gobbler.h, these should be 00006 // inline, not ACE_INLINE. 00007 // FUZZ: disable check_for_inline 00008 00009 #include "ace/ACE.h" 00010 #include "ace/OS_NS_unistd.h" 00011 #include "ace/OS_NS_fcntl.h" 00012 00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00014 00015 inline void 00016 ACE_Handle_Gobbler::close_remaining_handles (void) 00017 { 00018 ACE_Handle_Set_Iterator iter (this->handle_set_); 00019 for (ACE_HANDLE h = iter (); h != ACE_INVALID_HANDLE; h = iter ()) 00020 ACE_OS::close (h); 00021 } 00022 00023 inline 00024 ACE_Handle_Gobbler::~ACE_Handle_Gobbler (void) 00025 { 00026 this->close_remaining_handles (); 00027 } 00028 00029 inline int 00030 ACE_Handle_Gobbler::free_handles (size_t n_handles) 00031 { 00032 ACE_Handle_Set_Iterator iter (this->handle_set_); 00033 for (ACE_HANDLE h = iter (); 00034 h != ACE_INVALID_HANDLE && n_handles > 0; 00035 --n_handles, h = iter ()) 00036 ACE_OS::close (h); 00037 00038 return 0; 00039 } 00040 00041 inline int 00042 ACE_Handle_Gobbler::consume_handles (size_t n_handles_to_keep_available) 00043 { 00044 int result = 0; 00045 00046 #if defined(ACE_WIN32) 00047 // On Win32, this style of gobbling doesn't seem to work. 00048 ACE_UNUSED_ARG(n_handles_to_keep_available); 00049 00050 #else 00051 00052 while (1) 00053 { 00054 ACE_HANDLE handle = ACE_OS::open (ACE_DEV_NULL, O_WRONLY); 00055 00056 if (handle == ACE_INVALID_HANDLE) 00057 { 00058 if (ACE::out_of_handles (errno)) 00059 { 00060 result = this->free_handles (n_handles_to_keep_available); 00061 break; 00062 } 00063 else 00064 { 00065 result = -1; 00066 break; 00067 } 00068 } 00069 if (handle >= static_cast<ACE_HANDLE>(FD_SETSIZE)) 00070 break; 00071 this->handle_set_.set_bit (handle); 00072 } 00073 00074 #endif /* ACE_WIN32 */ 00075 00076 return result; 00077 } 00078 00079 ACE_END_VERSIONED_NAMESPACE_DECL