Marine Library  1.0
C++ library for Linux Networking Development
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
IFileDesc Class Referenceabstract

Abstract interface of fd (file descriptor). More...

#include <file.hh>

Inheritance diagram for IFileDesc:
Inheritance graph
[legend]

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
 

Detailed Description

Abstract interface of fd (file descriptor).

Constructor & Destructor Documentation

virtual IFileDesc::~IFileDesc ( )
inlinevirtual

Destroy this object.

Release any resources if necessary.

Member Function Documentation

bool IFileDesc::block ( bool  on)
inline

Set block/non-block for operations.

Parameters
on
  • true: all IO operations will be BLOCK by default
  • false: all IO operations will be NONBLOCK by default
Returns
true if succeeded; false otherwise
See also
ErrMsg
bool IFileDesc::deleted ( ) const
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.

Returns
true if file is deleted; false otherwise
static std::string IFileDesc::ErrMsg ( )
inlinestatic

Get latest errno and error message.

Returns
Description of latest error
int IFileDesc::fd ( ) const
inline

Get fd (file descriptor).

Returns
fd
virtual int IFileDesc::fdType ( ) const
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 kFdTypes are defined:

Type Id Value
CFile::kFdType 1
CTcpConnSocket::kFdType 2
CListenSocket::kFdType 3
CUdpSocket::kFdType 4
CPosixShmFile::kFdType 5
CEpoll::kFdType 6
Returns
Type id of this object
See also
kFdType

Implemented in CListenSocket, CTcpConnSocket, CUdpSocket, CFile, CEpoll, and CPosixShmFile.

virtual const char* IFileDesc::fdTypeName ( ) const
pure virtual

Get type name of this object.

Any concrete class derived from IFileDesc must give a readable name to identify itself.

Returns
Readable type name

Implemented in CListenSocket, CTcpConnSocket, CUdpSocket, CFile, CEpoll, and CPosixShmFile.

std::string IFileDesc::filename ( ) const
inline

Get file name opened by this object.

Returns
A file name, or an empty string if any error occurs
See also
ErrMsg
off_t IFileDesc::length ( ) const
inline

Get byte size of file opened by this object.

Returns
  • -1: Failed
  • others: Byte size of file
See also
ErrMsg
virtual std::string IFileDesc::toString ( ) const
inlinevirtual

Get readable description of this object.

Returns
Description string

Reimplemented in CFile, ISocket, CEpoll, and CPosixShmFile.

bool IFileDesc::valid ( ) const
inline

Test if this object is a valid file descriptor.

Returns
true if it's valid; false otherwise

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