# Passenger::FileDescriptor Class Reference

Wrapper class around a file descriptor integer, for RAII behavior. More...

`#include <FileDescriptor.h>`

List of all members.

## Public Member Functions
| FileDescriptor ()
| Creates a new empty FileDescriptor instance that has no underlying file descriptor.
| FileDescriptor (int fd)
| Creates a new FileDescriptor instance with the given fd as a handle.
void | close ()
| Close the underlying file descriptor.
| operator int () const
| Overloads the integer cast operator so that it will return the underlying file descriptor handle as an integer.

## Detailed Description

Wrapper class around a file descriptor integer, for RAII behavior.

A FileDescriptor object behaves just like an int, so that you can pass it to system calls such as read(). It performs reference counting. When the last copy of a FileDescriptor has been destroyed, the underlying file descriptor will be automatically closed. In this case, any close() system call errors are silently ignored. If you are interested in whether the close() system call succeeded, then you should call FileDescriptor::close().

This class is *not* thread-safe. It is safe to call system calls on the underlying file descriptor from multiple threads, but it's not safe to call FileDescriptor::close() from multiple threads if all those FileDescriptor objects point to the same underlying file descriptor.

## Constructor & Destructor Documentation

Passenger::FileDescriptor::FileDescriptor | ( |  | ) | `[inline]`

Creates a new empty FileDescriptor instance that has no underlying file descriptor.

Postcondition:
  *this == -1

Passenger::FileDescriptor::FileDescriptor | ( | int | fd | ) | `[inline]`

Creates a new FileDescriptor instance with the given fd as a handle.

Postcondition:
  *this == fd

## Member Function Documentation

void Passenger::FileDescriptor::close | ( |  | ) | `[inline]`

Close the underlying file descriptor.

If it was already closed, then nothing will happen. If there are multiple copies of this FileDescriptor then the underlying file descriptor will be closed for every one of them.

Exceptions:

  | SystemException | Something went wrong while closing the file descriptor.

Postcondition:
  *this == -1

Passenger::FileDescriptor::operator int | ( |  | ) | const`[inline]`

Overloads the integer cast operator so that it will return the underlying file descriptor handle as an integer.

Returns -1 if FileDescriptor::close() was called.

The documentation for this class was generated from the following file:

- FileDescriptor.h