MPD: FileDescriptor Class Reference

MPD 0.20.18

Public Member Functions | Static Public Member Functions | Protected Attributes
FileDescriptor Class Reference

An OO wrapper for a UNIX file descriptor. More...

`#include <FileDescriptor.hxx>`

## Public Member Functions
| FileDescriptor ()=default
constexpr | FileDescriptor (int _fd)
constexpr bool | operator== (FileDescriptor other) const
constexpr bool | IsDefined () const
constexpr int | Get () const
| Returns the file descriptor. More...
void | Set (int _fd) noexcept
int | Steal () noexcept
void | SetUndefined () noexcept
bool | Open (const char *pathname, int flags, mode_t mode=0666) noexcept
bool | OpenReadOnly (const char *pathname) noexcept
bool | OpenNonBlocking (const char *pathname) noexcept
void | SetNonBlocking () noexcept
| Enable non-blocking mode on this file descriptor. More...
void | SetBlocking () noexcept
| Enable blocking mode on this file descriptor. More...
bool | Duplicate (int new_fd) const noexcept
| Duplicate the file descriptor onto the given file descriptor. More...
bool | Close () noexcept
| Close the file descriptor. More...
bool | Rewind () noexcept
| Rewind the pointer to the beginning of the file. More...
off_t | Seek (off_t offset) noexcept
off_t | Skip (off_t offset) noexcept
gcc_pure off_t | Tell () const noexcept
gcc_pure off_t | GetSize () const noexcept
| Returns the size of the file in bytes, or -1 on error. More...
ssize_t | Read (void *buffer, size_t length) noexcept
ssize_t | Write (const void *buffer, size_t length) noexcept
int | Poll (short events, int timeout) const noexcept
int | WaitReadable (int timeout) const noexcept
int | WaitWritable (int timeout) const noexcept

## Static Public Member Functions
static constexpr FileDescriptor | Undefined ()
static bool | CreatePipe (FileDescriptor &r, FileDescriptor &w) noexcept

## Protected Attributes
int | fd

## Detailed Description

An OO wrapper for a UNIX file descriptor.

This class is unmanaged and trivial.

Definition at line 49 of file FileDescriptor.hxx.

## Constructor & Destructor Documentation

## ◆ FileDescriptor() [1/2]

FileDescriptor::FileDescriptor | ( |  | ) |
| default

## ◆ FileDescriptor() [2/2]

constexpr FileDescriptor::FileDescriptor | ( | int | _fd | ) |
| inlineexplicit

Definition at line 55 of file FileDescriptor.hxx.

## Member Function Documentation

## ◆ Close()

bool FileDescriptor::Close | ( |  | ) |
| inlinenoexcept

Close the file descriptor.

It is legal to call it on an "undefined" object. After this call, IsDefined() is guaranteed to return false, and this object may be reused.

Definition at line 136 of file FileDescriptor.hxx.

## ◆ CreatePipe()

static bool FileDescriptor::CreatePipe | ( | FileDescriptor & | r,
|  | FileDescriptor & | w
| ) |  |
| staticnoexcept

## ◆ Duplicate()

bool FileDescriptor::Duplicate | ( | int | new_fd | ) | const
| inlinenoexcept

Duplicate the file descriptor onto the given file descriptor.

Definition at line 114 of file FileDescriptor.hxx.

## ◆ Get()

constexpr int FileDescriptor::Get | ( |  | ) | const
| inline

Returns the file descriptor.

This may only be called if IsDefined() returns true.

Definition at line 69 of file FileDescriptor.hxx.

## ◆ GetSize()

gcc_pure off_t FileDescriptor::GetSize | ( |  | ) | const
| noexcept

Returns the size of the file in bytes, or -1 on error.

## ◆ IsDefined()

constexpr bool FileDescriptor::IsDefined | ( |  | ) | const
| inline

Definition at line 61 of file FileDescriptor.hxx.

## ◆ Open()

bool FileDescriptor::Open | ( | const char * | pathname,
|  | int | flags,
|  | mode_t | mode = `0666`
| ) |  |
| noexcept

## ◆ OpenNonBlocking()

bool FileDescriptor::OpenNonBlocking | ( | const char * | pathname | ) |
| noexcept

## ◆ OpenReadOnly()

bool FileDescriptor::OpenReadOnly | ( | const char * | pathname | ) |
| noexcept

## ◆ operator==()

constexpr bool FileDescriptor::operator== | ( | FileDescriptor | other | ) | const
| inline

Definition at line 57 of file FileDescriptor.hxx.

## ◆ Poll()

int FileDescriptor::Poll | ( | short | events,
|  | int | timeout
| ) |  | const
| noexcept

## ◆ Read()

ssize_t FileDescriptor::Read | ( | void * | buffer,
|  | size_t | length
| ) |  |
| inlinenoexcept

Definition at line 164 of file FileDescriptor.hxx.

## ◆ Rewind()

bool FileDescriptor::Rewind | ( |  | ) |
| noexcept

Rewind the pointer to the beginning of the file.

## ◆ Seek()

off_t FileDescriptor::Seek | ( | off_t | offset | ) |
| inlinenoexcept

Definition at line 145 of file FileDescriptor.hxx.

## ◆ Set()

void FileDescriptor::Set | ( | int | _fd | ) |
| inlinenoexcept

Definition at line 73 of file FileDescriptor.hxx.

## ◆ SetBlocking()

void FileDescriptor::SetBlocking | ( |  | ) |
| noexcept

Enable blocking mode on this file descriptor.

## ◆ SetNonBlocking()

void FileDescriptor::SetNonBlocking | ( |  | ) |
| noexcept

Enable non-blocking mode on this file descriptor.

## ◆ SetUndefined()

void FileDescriptor::SetUndefined | ( |  | ) |
| inlinenoexcept

Definition at line 85 of file FileDescriptor.hxx.

## ◆ Skip()

off_t FileDescriptor::Skip | ( | off_t | offset | ) |
| inlinenoexcept

Definition at line 149 of file FileDescriptor.hxx.

## ◆ Steal()

int FileDescriptor::Steal | ( |  | ) |
| inlinenoexcept

Definition at line 77 of file FileDescriptor.hxx.

## ◆ Tell()

gcc_pure off_t FileDescriptor::Tell | ( |  | ) | const
| inlinenoexcept

Definition at line 154 of file FileDescriptor.hxx.

## ◆ Undefined()

static constexpr FileDescriptor FileDescriptor::Undefined | ( |  | ) |
| inlinestatic

Definition at line 89 of file FileDescriptor.hxx.

## ◆ WaitReadable()

int FileDescriptor::WaitReadable | ( | int | timeout | ) | const
| noexcept

## ◆ WaitWritable()

int FileDescriptor::WaitWritable | ( | int | timeout | ) | const
| noexcept

## ◆ Write()

ssize_t FileDescriptor::Write | ( | const void * | buffer,
|  | size_t | length
| ) |  |
| inlinenoexcept

Definition at line 168 of file FileDescriptor.hxx.

## Field Documentation

## ◆ fd

int FileDescriptor::fd
| protected

Definition at line 51 of file FileDescriptor.hxx.

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

- system/FileDescriptor.hxx