Marine Library
1.0
C++ library for Linux Networking Development
|
Abstract interface of fd (file descriptor). More...
#include <file.hh>
Public Member Functions | |
IFileDesc () | |
Construct a default object. | |
virtual | ~IFileDesc () |
Destroy this object. More... | |
bool | valid () const |
Test if this object is a valid file descriptor. More... | |
int | fd () const |
Get fd (file descriptor). More... | |
virtual int | fdType () const =0 |
Get type id of this object. More... | |
virtual const char * | fdTypeName () const =0 |
Get type name of this object. More... | |
std::string | filename () const |
Get file name opened by this object. More... | |
off_t | length () const |
Get byte size of file opened by this object. More... | |
bool | deleted () const |
Test if file is deleted. More... | |
bool | block (bool on) |
Set block/non-block for operations. More... | |
void | close () |
Close this fd. | |
virtual std::string | toString () const |
Get readable description of this object. More... | |
Static Public Member Functions | |
static std::string | ErrMsg () |
Get latest errno and error message. More... | |
Static Public Attributes | |
static const int | kInvalidFd = -1 |
Abstract interface of fd (file descriptor).
|
inlinevirtual |
Destroy this object.
Release any resources if necessary.
|
inline |
Set block/non-block for operations.
on |
|
true
if succeeded; false
otherwise
|
inline |
Test if file is deleted.
A file could be removed even if you're reading or writing it. So it's necessary to test this status, or you may lost all changes to the file.
true
if file is deleted; false
otherwise
|
inlinestatic |
Get latest errno
and error message.
|
inline |
Get fd (file descriptor).
|
pure virtual |
Get type id of this object.
Any concrete class derived from IFileDesc shall define a distinct type id named kFdType
, so it's possible to check this id and determine what the object really is.
Currently following kFdType
s are defined:
Type Id | Value |
---|---|
CFile::kFdType | 1 |
CTcpConnSocket::kFdType | 2 |
CListenSocket::kFdType | 3 |
CUdpSocket::kFdType | 4 |
CPosixShmFile::kFdType | 5 |
CEpoll::kFdType | 6 |
Implemented in CListenSocket, CTcpConnSocket, CUdpSocket, CFile, CEpoll, and CPosixShmFile.
|
pure virtual |
Get type name of this object.
Any concrete class derived from IFileDesc must give a readable name to identify itself.
Implemented in CListenSocket, CTcpConnSocket, CUdpSocket, CFile, CEpoll, and CPosixShmFile.
|
inline |
Get file name opened by this object.
|
inline |
Get byte size of file opened by this object.
-1
: Failed
|
inlinevirtual |
Get readable description of this object.
Reimplemented in CFile, ISocket, CEpoll, and CPosixShmFile.
|
inline |
Test if this object is a valid file descriptor.
true
if it's valid; false
otherwise