UI::Util::FileDescriptor Class Reference

File Descriptor Holder Class. More...

`#include <File.hpp>`

Inheritance diagram for UI::Util::FileDescriptor:
Collaboration diagram for UI::Util::FileDescriptor:

## Public Types

enum | ErrorCode { OpenErr_ = 1 , ReadErr_ , WriteErr_ , LockErr_ , UnlockErr_ , BindErr_ , ConnectErr_ , UnblockErr_ , ListenErr_ , ShutdownErr_ }
| Error codes for exceptions.
typedef CodeException< ErrorCode > | Exception
| Exceptions for this class.

## Public Member Functions

| FileDescriptor (int fd=-1, bool closeFd=false)
| Constructor from file descriptor.
virtual | ~FileDescriptor ()
| Destructor.
virtual std::streamsize | read (void *const buf, std::streamsize count)
| C++ like virtual read method.
virtual std::streamsize | write (void const *const buf, std::streamsize count)
| C++ like virtual erite method.
int | getFd () const
| Get file descriptor.

## Static Public Member Functions

static void | fdClose (int const &fd, std::string const &id, bool const &doClose=true)
| Helper to close file descriptors from destructors.

## Protected Member Functions

void | init (int fd, bool closeFd=false)
| To be called in a constructor.

## Protected Attributes

int | fd_
| The file descriptor that is managed.

## Detailed Description

File Descriptor Holder Class.

See also
  read(2), write(2)

This should encapsulate system calls on file descriptors, and automate descriptor closing.

Examples
  FileLock.cpp.

## Constructor & Destructor Documentation

## FileDescriptor()

UI::Util::FileDescriptor::FileDescriptor | ( | int | fd = `-1`,
|  | bool | closeFd = `false`
| ) |  |

Constructor from file descriptor.

Parameters

  fd | Already opened file descriptor
  closeFd | Whether to call close(2) in destructor

This constructor takes an already opened file descriptor. The destructor will not call close on this descriptor.

References init().

## ~FileDescriptor()

UI::Util::FileDescriptor::~FileDescriptor | ( |  | ) |

virtual

Destructor.

This will close the file descriptor via close(2), unless it was constructed by an already opened descriptor.

It will never delete the file, even if it got created by the constructor.

References fd_, and fdClose().

## Member Function Documentation

## read()

std::streamsize UI::Util::FileDescriptor::read | ( | void *const | buf,
|  | std::streamsize | count
| ) |  |

virtual

C++ like virtual read method.

This default implementation uses read(2).

Reimplemented in UI::Util::Socket.

References fd_, getFd(), and UI_THROW_CODE.

## write()

std::streamsize UI::Util::FileDescriptor::write | ( | void const *const | buf,
|  | std::streamsize | count
| ) |  |

virtual

C++ like virtual erite method.

This default implementation uses write(2).

Reimplemented in UI::Util::Socket.

References fd_, getFd(), and UI_THROW_CODE.

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

- File.hpp
- File.cpp