Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class handle

boost::process::handle

Synopsis

// In header: <boost/process/handle.hpp>


class handle {
public:
  // types
  typedef NativeSystemHandle native_type;

  // member classes/structs/unions

  class impl {
  public:
    // types
    typedef handle::native_type native_type;

    // construct/copy/destruct
    impl(native_type, close_type);
    ~impl();

    // public member functions
    bool valid() const;
    void close() ;
    native_type native() const;
    native_type release() ;
  };
  enum close_type;

  // construct/copy/destruct
  handle();
  handle(native_type, close_type = handle::do_close);

  // public member functions
  bool valid() const;
  void close() ;
  native_type native() const;
  native_type release() ;

  // private static functions
  static const native_type invalid_handle() ;
};

Description

RAII model for handles.

The handle class is a RAII model for native handles. This class wraps one of such handles grabbing its ownership, and automaticaly closes it upon destruction. It is used to avoid leaking open handles, shall an unexpected execution trace occur.

handle public types

  1. typedef NativeSystemHandle native_type;

    Opaque name for the native handle type.

    On POSIX systems NativeSystemHandle is an integer type while it is a HANDLE on Windows systems.

handle public construct/copy/destruct

  1. handle();

    Constructs an invalid handle.

    valid()

  2. handle(native_type native, close_type close = handle::do_close);

    Constructs a handle from a native handle.

    This constructor creates a new handle object that takes ownership of the given native handle. If close is set to handle::dont_close the native handle is not closed upon destruction. The user must not close native if it is owned by a handle object. Ownership can be reclaimed using release().

    release()

handle public member functions

  1. bool valid() const;

    Checks whether the handle is valid or not.

    Returns:

    true if the handle is valid; false otherwise.

  2. void close() ;

    Closes the handle.

    Postconditions:

    The handle is invalid.

    The native handle is closed.

  3. native_type native() const;

    Gets the native handle.

    The caller can issue any operation on it except closing it. If closing is required, release() shall be used.

    Returns:

    The native handle.

  4. native_type release() ;

    Reclaims ownership of the native handle.

    The caller is responsible of closing the native handle.

    Postconditions:

    The handle is invalid.

    Returns:

    The native handle.

handle private static functions

  1. static const native_type invalid_handle() ;

    Constant function representing an invalid handle value.

    Returns the platform-specific handle value that represents an invalid handle. This is a constant function rather than a regular constant because, in the latter case, we cannot define it under Windows due to the value being of a complex type.


PrevUpHomeNext