Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

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 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...


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 35 of file Handle_Gobbler.h.


Member Typedef Documentation

typedef ACE_Unbounded_Set<ACE_HANDLE> 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 25 of file Handle_Gobbler.i.

References close_remaining_handles.

00026 {
00027   this->close_remaining_handles ();
00028 }


Member Function Documentation

void ACE_Handle_Gobbler::close_remaining_handles void    [inline]
 

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 }

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 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 }

int ACE_Handle_Gobbler::free_handles size_t    n_handles [inline]
 

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 }


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 close_remaining_handles, consume_handles, and free_handles.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:48:18 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002