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

Representation of epoll(7). More...

#include <epoll.hh>

Inheritance diagram for CEpoll:
Inheritance graph
[legend]
Collaboration diagram for CEpoll:
Collaboration graph
[legend]

Public Member Functions

int fdType () const
 Get fd (file descriptor) type identifier. More...
 
const char * fdTypeName () const
 Get fd (file identifier) type name. More...
 
bool create ()
 Initialize epoll. More...
 
bool addFd (int fd, uint32_t flags, bool mod=true)
 Add fd (file descriptor) to epoll. More...
 
bool modFd (int fd, uint32_t flags, bool add=true)
 Modify flags of an fd (file descriptor). More...
 
bool delFd (int fd)
 Remove an fd (file descriptor) from epoll. More...
 
bool wait (int timeoutMs=-1)
 Wait for epoll events. More...
 
size_t size () const
 Get number of file descriptors that have pending events. More...
 
const CEpollEventoperator[] (size_t i) const
 Get events of a ready file descriptor. More...
 
std::string toString () const
 Get readable description. More...
 
- Public Member Functions inherited from IFileDesc
 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...
 
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.
 

Static Public Attributes

static const int kFdType = 6
 
- Static Public Attributes inherited from IFileDesc
static const int kInvalidFd = -1
 

Additional Inherited Members

- Static Public Member Functions inherited from IFileDesc
static std::string ErrMsg ()
 Get latest errno and error message. More...
 

Detailed Description

Representation of epoll(7).

Member Function Documentation

bool CEpoll::addFd ( int  fd,
uint32_t  flags,
bool  mod = true 
)
inline

Add fd (file descriptor) to epoll.

Parameters
fdFile descriptor, a non-negative number
flagsA bit mask of events to monitor, e.g. EPOLLIN, EPOLLOUT
mod
  • true: If fd is already in epoll, modify its flags
  • false: If fd is already in epoll, this operation will fail
Returns
true if succeeded; false otherwise
bool CEpoll::create ( )
inline

Initialize epoll.

Returns
true if succeeded; false otherwise
bool CEpoll::delFd ( int  fd)
inline

Remove an fd (file descriptor) from epoll.

Parameters
fdFile descriptor, a non-negative number
Returns
true if succeeded; false otherwise
int CEpoll::fdType ( ) const
inlinevirtual

Get fd (file descriptor) type identifier.

Returns
6

Implements IFileDesc.

const char* CEpoll::fdTypeName ( ) const
inlinevirtual

Get fd (file identifier) type name.

Returns
"CEpoll"

Implements IFileDesc.

bool CEpoll::modFd ( int  fd,
uint32_t  flags,
bool  add = true 
)
inline

Modify flags of an fd (file descriptor).

Parameters
fdFile descriptor, a non-negative number
flagsA bit mask of events to monitor, e.g. EPOLLIN, EPOLLOUT
add
  • true: If fd is not in epoll, add it
  • false: If fd is not in epoll, this operation will fail
Returns
const CEpollEvent& CEpoll::operator[] ( size_t  i) const
inline

Get events of a ready file descriptor.

Parameters
iIndex of ready file descriptors list
Returns
Readonly events object for the file descriptor
size_t CEpoll::size ( ) const
inline

Get number of file descriptors that have pending events.

Returns
Number of ready file descriptors
std::string CEpoll::toString ( ) const
inlinevirtual

Get readable description.

Returns
Readable description of this object

Reimplemented from IFileDesc.

bool CEpoll::wait ( int  timeoutMs = -1)
inline

Wait for epoll events.

This function checks if there are pending events, and blocks current thread for an amount of time if necessary.

Parameters
timeoutMs
  • -1: Wait forever if there is no events
  • 0: Return immediately no matter there are events or not
  • Positive Number: Milliseconds to wait if there is no events
Returns
true if there are events; false if time is out and there is no event

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