#include <Handle_Gobbler.h>
Collaboration diagram for ACE_Handle_Gobbler:

Public Methods | |
| ~ACE_Handle_Gobbler (void) | |
| Destructor. Cleans up any remaining handles. More... | |
| int | consume_handles (size_t n_handles_to_keep_available) |
| int | free_handles (size_t n_handles) |
| Free up <n_handles>. More... | |
| void | close_remaining_handles (void) |
| All remaining handles are closed. More... | |
Private Types | |
| typedef ACE_Unbounded_Set< ACE_HANDLE > | HANDLE_SET |
Private Attributes | |
| HANDLE_SET | handle_set_ |
| The container which holds the open descriptors. More... | |
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 35 of file Handle_Gobbler.h.
|
|
Definition at line 57 of file Handle_Gobbler.h. |
|
|
Destructor. Cleans up any remaining handles.
Definition at line 25 of file Handle_Gobbler.i. References close_remaining_handles.
00026 {
00027 this->close_remaining_handles ();
00028 }
|
|
|
All remaining handles are closed.
Definition at line 8 of file Handle_Gobbler.i. References ACE_Unbounded_Set< ACE_HANDLE >::begin, ACE_OS::close, ACE_Unbounded_Set< ACE_HANDLE >::end, and handle_set_. Referenced by ~ACE_Handle_Gobbler.
00009 {
00010 HANDLE_SET::iterator iterator =
00011 this->handle_set_.begin ();
00012
00013 HANDLE_SET::iterator end =
00014 this->handle_set_.end ();
00015
00016 for (;
00017 iterator != end;
00018 ++iterator)
00019 {
00020 ACE_OS::close (*iterator);
00021 }
00022 }
|
|
|
Handles are opened continously until the process runs out of them, and then <n_handles_to_keep_available> handles are closed (freed) thereby making them usable in the future. Definition at line 52 of file Handle_Gobbler.i. References ACE_DEV_NULL, free_handles, handle_set_, ACE_Unbounded_Set< ACE_HANDLE >::insert, ACE_OS::open, and ACE::out_of_handles.
00053 {
00054 int result = 0;
00055
00056 #if defined(ACE_WIN32)
00057 // On Win32, this style of gobbling doesn't seem to work.
00058 ACE_UNUSED_ARG(n_handles_to_keep_available);
00059
00060 #else
00061
00062 while (1)
00063 {
00064 ACE_HANDLE handle = ACE_OS::open (ACE_DEV_NULL, O_WRONLY);
00065
00066 if (handle == ACE_INVALID_HANDLE)
00067 {
00068 if (ACE::out_of_handles (errno))
00069 {
00070 result = this->free_handles (n_handles_to_keep_available);
00071 break;
00072 }
00073 else
00074 {
00075 result = -1;
00076 break;
00077 }
00078 }
00079
00080 result = this->handle_set_.insert (handle);
00081 if (result == -1)
00082 break;
00083 }
00084
00085 #endif /* ACE_WIN32 */
00086
00087 return result;
00088 }
|
|
|
Free up <n_handles>.
Definition at line 31 of file Handle_Gobbler.i. References ACE_Unbounded_Set< ACE_HANDLE >::begin, ACE_OS::close, ACE_Unbounded_Set< ACE_HANDLE >::end, and handle_set_. Referenced by consume_handles.
00032 {
00033 HANDLE_SET::iterator iterator =
00034 this->handle_set_.begin ();
00035
00036 HANDLE_SET::iterator end =
00037 this->handle_set_.end ();
00038
00039 for (;
00040 iterator != end && n_handles > 0;
00041 ++iterator, --n_handles)
00042 {
00043 int result = ACE_OS::close (*iterator);
00044 if (result != 0)
00045 return result;
00046 }
00047
00048 return 0;
00049 }
|
|
|
The container which holds the open descriptors.
Definition at line 60 of file Handle_Gobbler.h. Referenced by close_remaining_handles, consume_handles, and free_handles. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002