00001 // -*- C++ -*- 00002 // 00003 // $Id: Handle_Gobbler.inl 77790 2007-03-23 15:50:07Z shuston $ 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/OS_NS_unistd.h" 00010 #include "ace/OS_NS_fcntl.h" 00011 00012 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00013 00014 inline void 00015 ACE_Handle_Gobbler::close_remaining_handles (void) 00016 { 00017 ACE_Handle_Set_Iterator iter (this->handle_set_); 00018 for (ACE_HANDLE h = iter (); h != ACE_INVALID_HANDLE; h = iter ()) 00019 ACE_OS::close (h); 00020 } 00021 00022 inline 00023 ACE_Handle_Gobbler::~ACE_Handle_Gobbler (void) 00024 { 00025 this->close_remaining_handles (); 00026 } 00027 00028 inline int 00029 ACE_Handle_Gobbler::free_handles (size_t n_handles) 00030 { 00031 ACE_Handle_Set_Iterator iter (this->handle_set_); 00032 for (ACE_HANDLE h = iter (); 00033 h != ACE_INVALID_HANDLE && n_handles > 0; 00034 --n_handles, h = iter ()) 00035 ACE_OS::close (h); 00036 00037 return 0; 00038 } 00039 00040 inline int 00041 ACE_Handle_Gobbler::consume_handles (size_t n_handles_to_keep_available) 00042 { 00043 int result = 0; 00044 00045 #if defined(ACE_WIN32) 00046 // On Win32, this style of gobbling doesn't seem to work. 00047 ACE_UNUSED_ARG(n_handles_to_keep_available); 00048 00049 #else 00050 00051 while (1) 00052 { 00053 ACE_HANDLE handle = ACE_OS::open (ACE_DEV_NULL, O_WRONLY); 00054 00055 if (handle == ACE_INVALID_HANDLE) 00056 { 00057 if (ACE::out_of_handles (errno)) 00058 { 00059 result = this->free_handles (n_handles_to_keep_available); 00060 break; 00061 } 00062 else 00063 { 00064 result = -1; 00065 break; 00066 } 00067 } 00068 if (handle >= FD_SETSIZE) 00069 break; 00070 this->handle_set_.set_bit (handle); 00071 } 00072 00073 #endif /* ACE_WIN32 */ 00074 00075 return result; 00076 } 00077 00078 ACE_END_VERSIONED_NAMESPACE_DECL