ui-utilcpp 1.10.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
UI::Util::FileDescriptor Class Reference

File Descriptor Holder Class. More...

#include <File.hpp>

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

Public Types

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

Public Member Functions

 FileDescriptor (int fd=-1, bool closeFd=false)
 Constructor from file descriptor. More...
 
virtual ~FileDescriptor ()
 Destructor. More...
 
virtual std::streamsize read (void *const buf, std::streamsize count)
 C++ like virtual read method. More...
 
virtual std::streamsize write (void const *const buf, std::streamsize count)
 C++ like virtual erite method. More...
 
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
fdAlready opened file descriptor
closeFdWhether 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_, 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_, and UI_THROW_CODE.


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