00001 // -*- C++ -*- 00002 // 00003 // Handle_Gobbler.inl,v 4.2 2005/10/28 16:14:52 ossama Exp 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 HANDLE_SET::iterator iterator = 00018 this->handle_set_.begin (); 00019 00020 HANDLE_SET::iterator end = 00021 this->handle_set_.end (); 00022 00023 for (; 00024 iterator != end; 00025 ++iterator) 00026 { 00027 ACE_OS::close (*iterator); 00028 } 00029 } 00030 00031 inline 00032 ACE_Handle_Gobbler::~ACE_Handle_Gobbler (void) 00033 { 00034 this->close_remaining_handles (); 00035 } 00036 00037 inline int 00038 ACE_Handle_Gobbler::free_handles (size_t n_handles) 00039 { 00040 HANDLE_SET::iterator iterator = 00041 this->handle_set_.begin (); 00042 00043 HANDLE_SET::iterator end = 00044 this->handle_set_.end (); 00045 00046 for (; 00047 iterator != end && n_handles > 0; 00048 ++iterator, --n_handles) 00049 { 00050 int result = ACE_OS::close (*iterator); 00051 if (result != 0) 00052 return result; 00053 } 00054 00055 return 0; 00056 } 00057 00058 inline int 00059 ACE_Handle_Gobbler::consume_handles (size_t n_handles_to_keep_available) 00060 { 00061 int result = 0; 00062 00063 #if defined(ACE_WIN32) 00064 // On Win32, this style of gobbling doesn't seem to work. 00065 ACE_UNUSED_ARG(n_handles_to_keep_available); 00066 00067 #else 00068 00069 while (1) 00070 { 00071 ACE_HANDLE handle = ACE_OS::open (ACE_DEV_NULL, O_WRONLY); 00072 00073 if (handle == ACE_INVALID_HANDLE) 00074 { 00075 if (ACE::out_of_handles (errno)) 00076 { 00077 result = this->free_handles (n_handles_to_keep_available); 00078 break; 00079 } 00080 else 00081 { 00082 result = -1; 00083 break; 00084 } 00085 } 00086 00087 result = this->handle_set_.insert (handle); 00088 if (result == -1) 00089 break; 00090 } 00091 00092 #endif /* ACE_WIN32 */ 00093 00094 return result; 00095 } 00096 00097 ACE_END_VERSIONED_NAMESPACE_DECL