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::FileDescriptor ( )
default
constexpr FileDescriptor::FileDescriptor ( int  _fd)
inlineexplicit

Definition at line 55 of file FileDescriptor.hxx.

Member Function Documentation

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.

static bool FileDescriptor::CreatePipe ( FileDescriptor r,
FileDescriptor w 
)
staticnoexcept
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.

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.

gcc_pure off_t FileDescriptor::GetSize ( ) const
noexcept

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

constexpr bool FileDescriptor::IsDefined ( ) const
inline

Definition at line 61 of file FileDescriptor.hxx.

bool FileDescriptor::Open ( const char *  pathname,
int  flags,
mode_t  mode = 0666 
)
noexcept
bool FileDescriptor::OpenNonBlocking ( const char *  pathname)
noexcept
bool FileDescriptor::OpenReadOnly ( const char *  pathname)
noexcept
constexpr bool FileDescriptor::operator== ( FileDescriptor  other) const
inline

Definition at line 57 of file FileDescriptor.hxx.

int FileDescriptor::Poll ( short  events,
int  timeout 
) const
noexcept
ssize_t FileDescriptor::Read ( void *  buffer,
size_t  length 
)
inlinenoexcept

Definition at line 164 of file FileDescriptor.hxx.

bool FileDescriptor::Rewind ( )
noexcept

Rewind the pointer to the beginning of the file.

off_t FileDescriptor::Seek ( off_t  offset)
inlinenoexcept

Definition at line 145 of file FileDescriptor.hxx.

void FileDescriptor::Set ( int  _fd)
inlinenoexcept

Definition at line 73 of file FileDescriptor.hxx.

void FileDescriptor::SetBlocking ( )
noexcept

Enable blocking mode on this file descriptor.

void FileDescriptor::SetNonBlocking ( )
noexcept

Enable non-blocking mode on this file descriptor.

void FileDescriptor::SetUndefined ( )
inlinenoexcept

Definition at line 85 of file FileDescriptor.hxx.

off_t FileDescriptor::Skip ( off_t  offset)
inlinenoexcept

Definition at line 149 of file FileDescriptor.hxx.

int FileDescriptor::Steal ( )
inlinenoexcept

Definition at line 77 of file FileDescriptor.hxx.

gcc_pure off_t FileDescriptor::Tell ( ) const
inlinenoexcept

Definition at line 154 of file FileDescriptor.hxx.

static constexpr FileDescriptor FileDescriptor::Undefined ( )
inlinestatic

Definition at line 89 of file FileDescriptor.hxx.

int FileDescriptor::WaitReadable ( int  timeout) const
noexcept
int FileDescriptor::WaitWritable ( int  timeout) const
noexcept
ssize_t FileDescriptor::Write ( const void *  buffer,
size_t  length 
)
inlinenoexcept

Definition at line 168 of file FileDescriptor.hxx.

Field Documentation

int FileDescriptor::fd
protected

Definition at line 51 of file FileDescriptor.hxx.


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