#include <Handle_Gobbler.h>
Collaboration diagram for ACE_Handle_Gobbler:
Public Member Functions | |
~ACE_Handle_Gobbler (void) | |
Destructor. Cleans up any remaining handles. | |
int | consume_handles (size_t n_handles_to_keep_available) |
int | free_handles (size_t n_handles) |
Free up n_handles. | |
void | close_remaining_handles (void) |
All remaining handles are closed. | |
Private Types | |
typedef ACE_Unbounded_Set< ACE_HANDLE > | HANDLE_SET |
Private Attributes | |
HANDLE_SET | handle_set_ |
The container which holds the open descriptors. |
This is useful when we need to control the number of handles available for a process. This class is mostly used for testing purposes.
Definition at line 36 of file Handle_Gobbler.h.
|
Definition at line 58 of file Handle_Gobbler.h. |
|
Destructor. Cleans up any remaining handles.
Definition at line 32 of file Handle_Gobbler.inl. References close_remaining_handles().
00033 { 00034 this->close_remaining_handles (); 00035 } |
|
All remaining handles are closed.
Definition at line 15 of file Handle_Gobbler.inl. References ACE_Unbounded_Set< ACE_HANDLE >::begin(), ACE_OS::close(), ACE_Unbounded_Set< ACE_HANDLE >::end(), and handle_set_. Referenced by ~ACE_Handle_Gobbler().
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 } |
|
Handles are opened continously until the process runs out of them, and then handles are closed (freed) thereby making them usable in the future. Definition at line 59 of file Handle_Gobbler.inl. References ACE_DEV_NULL, free_handles(), handle_set_, ACE_Unbounded_Set< ACE_HANDLE >::insert(), ACE_OS::open(), and ACE::out_of_handles().
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 } |
|
Free up n_handles.
Definition at line 38 of file Handle_Gobbler.inl. References ACE_Unbounded_Set< ACE_HANDLE >::begin(), ACE_OS::close(), ACE_Unbounded_Set< ACE_HANDLE >::end(), and handle_set_. Referenced by consume_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 } |
|
The container which holds the open descriptors.
Definition at line 61 of file Handle_Gobbler.h. Referenced by close_remaining_handles(), consume_handles(), and free_handles(). |