Public Member Functions | Private Types | Private Attributes

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

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


Member Function Documentation

void ACE_Handle_Gobbler::close_remaining_handles ( void   )  [inline]

All remaining handles are closed.

Definition at line 16 of file Handle_Gobbler.inl.

{
  ACE_Handle_Set_Iterator iter (this->handle_set_);
  for (ACE_HANDLE h = iter (); h != ACE_INVALID_HANDLE; h = iter ())
    ACE_OS::close (h);
}

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

{
  int result = 0;

#if defined(ACE_WIN32)
  // On Win32, this style of gobbling doesn't seem to work.
  ACE_UNUSED_ARG(n_handles_to_keep_available);

#else

  while (1)
    {
      ACE_HANDLE handle = ACE_OS::open (ACE_DEV_NULL, O_WRONLY);

      if (handle == ACE_INVALID_HANDLE)
        {
          if (ACE::out_of_handles (errno))
            {
              result = this->free_handles (n_handles_to_keep_available);
              break;
            }
          else
            {
              result = -1;
              break;
            }
        }
      if (handle >= static_cast<ACE_HANDLE>(FD_SETSIZE))
        break;
      this->handle_set_.set_bit (handle);
    }

#endif /* ACE_WIN32 */

  return result;
}

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

Free up n_handles.

Definition at line 30 of file Handle_Gobbler.inl.

{
  ACE_Handle_Set_Iterator iter (this->handle_set_);
  for (ACE_HANDLE h = iter ();
       h != ACE_INVALID_HANDLE && n_handles > 0;
       --n_handles, h = iter ())
    ACE_OS::close (h);

  return 0;
}


Member Data Documentation

The container which holds the open descriptors.

Definition at line 60 of file Handle_Gobbler.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines