ui-utilcpp
1.8.5
|
File Descriptor Holder Class. More...
#include <File.hpp>
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. 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. | |
File Descriptor Holder Class.
This should encapsulate system calls on file descriptors, and automate descriptor closing.
UI::Util::FileDescriptor::FileDescriptor | ( | int | fd = -1 , |
bool | closeFd = false |
||
) |
Constructor from file descriptor.
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.
|
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.
|
virtual |
C++ like virtual read method.
This default implementation uses read(2).
Reimplemented in UI::Util::Socket.
References UI_THROW_CODE.
|
virtual |
C++ like virtual erite method.
This default implementation uses write(2).
Reimplemented in UI::Util::Socket.
References UI_THROW_CODE.