libept
Public Member Functions | Protected Attributes | List of all members
ept::sys::FileDescriptor Class Reference

Common operations on file descriptors. More...

#include <sys.h>

Inheritance diagram for ept::sys::FileDescriptor:
ept::sys::NamedFileDescriptor ept::sys::File ept::sys::Path

Public Member Functions

 FileDescriptor ()
 
 FileDescriptor (FileDescriptor &&o)
 
 FileDescriptor (int fd)
 
virtual ~FileDescriptor ()
 
virtual void throw_error (const char *desc)
 Throw an exception based on errno and the given message. More...
 
void close ()
 
void fstat (struct stat &st)
 
void fchmod (mode_t mode)
 
size_t write (const void *buf, size_t count)
 
void write_all (const void *buf, size_t count)
 Write all the data in buf, retrying partial writes. More...
 
MMap mmap (size_t length, int prot, int flags, off_t offset=0)
 
 operator int () const
 

Protected Attributes

int fd = -1
 

Detailed Description

Common operations on file descriptors.

Except when documented otherwise, methods of this class are just thin wrappers around the libc functions with the same name, that check error results and throw exceptions if the functions failed.

Implementing what to do on construction and destruction is left to the subclassers: at the FileDescriptor level, the destructor does nothing and leaves the file descriptor open.

Constructor & Destructor Documentation

◆ FileDescriptor() [1/3]

ept::sys::FileDescriptor::FileDescriptor ( )

◆ FileDescriptor() [2/3]

ept::sys::FileDescriptor::FileDescriptor ( FileDescriptor &&  o)

◆ FileDescriptor() [3/3]

ept::sys::FileDescriptor::FileDescriptor ( int  fd)

◆ ~FileDescriptor()

ept::sys::FileDescriptor::~FileDescriptor ( )
virtual

Member Function Documentation

◆ close()

void ept::sys::FileDescriptor::close ( )

◆ fchmod()

void ept::sys::FileDescriptor::fchmod ( mode_t  mode)

References fd, and throw_error().

Referenced by ept::sys::write_file_atomically().

◆ fstat()

void ept::sys::FileDescriptor::fstat ( struct stat st)

References fd, and throw_error().

Referenced by ept::sys::read_file().

◆ mmap()

MMap ept::sys::FileDescriptor::mmap ( size_t  length,
int  prot,
int  flags,
off_t  offset = 0 
)

References fd, res, and throw_error().

Referenced by ept::sys::read_file().

◆ operator int()

ept::sys::FileDescriptor::operator int ( ) const
inline

◆ throw_error()

void ept::sys::FileDescriptor::throw_error ( const char *  desc)
virtual

Throw an exception based on errno and the given message.

This can be overridden by subclasses that may have more information about the file descriptor, so that they can generate more descriptive messages.

Reimplemented in ept::sys::NamedFileDescriptor.

Referenced by close(), fchmod(), fstat(), mmap(), and write().

◆ write()

size_t ept::sys::FileDescriptor::write ( const void *  buf,
size_t  count 
)

References fd, res, and throw_error().

Referenced by write_all().

◆ write_all()

void ept::sys::FileDescriptor::write_all ( const void *  buf,
size_t  count 
)

Write all the data in buf, retrying partial writes.

References write().

Referenced by ept::sys::write_file(), and ept::sys::write_file_atomically().

Member Data Documentation

◆ fd

int ept::sys::FileDescriptor::fd = -1
protected

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