ACE_Handle_Gobbler Class Reference

This class gobbles up handles. More...

#include <Handle_Gobbler.h>

Collaboration diagram for ACE_Handle_Gobbler:

Collaboration graph
[legend]
List of all members.

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_Handle_Set HANDLE_SET

Private Attributes

HANDLE_SET handle_set_
 The container which holds the open descriptors.

Detailed Description

This class gobbles up handles.

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.


Member Typedef Documentation

typedef ACE_Handle_Set ACE_Handle_Gobbler::HANDLE_SET [private]

Definition at line 57 of file Handle_Gobbler.h.


Constructor & Destructor Documentation

ACE_Handle_Gobbler::~ACE_Handle_Gobbler ( void   )  [inline]

Destructor. Cleans up any remaining handles.

Definition at line 23 of file Handle_Gobbler.inl.

References close_remaining_handles().

00024 {
00025   this->close_remaining_handles ();
00026 }


Member Function Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Handle_Gobbler::close_remaining_handles ( void   )  [inline]

All remaining handles are closed.

Definition at line 15 of file Handle_Gobbler.inl.

References ACE_OS::close().

Referenced by ~ACE_Handle_Gobbler().

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 }

int ACE_Handle_Gobbler::consume_handles ( size_t  n_handles_to_keep_available  )  [inline]

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 41 of file Handle_Gobbler.inl.

References ACE_DEV_NULL, free_handles(), handle_set_, ACE_OS::open(), ACE::out_of_handles(), and ACE_Handle_Set::set_bit().

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 }

int ACE_Handle_Gobbler::free_handles ( size_t  n_handles  )  [inline]

Free up n_handles.

Definition at line 29 of file Handle_Gobbler.inl.

References ACE_OS::close().

Referenced by consume_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 }


Member Data Documentation

HANDLE_SET ACE_Handle_Gobbler::handle_set_ [private]

The container which holds the open descriptors.

Definition at line 60 of file Handle_Gobbler.h.

Referenced by consume_handles().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:09 2010 for ACE by  doxygen 1.4.7