senf::scheduler::FdEvent Class Reference

File descriptor event. More...

#include <senf/Scheduler/FdEvent.hh>

Inheritance diagram for senf::scheduler::FdEvent:

Classes

struct  DuplicateEventRegistrationException
 

Public Types

enum  Events {
  EV_NULL = 0, EV_READ = detail::FdManager::EV_READ, EV_PRIO = detail::FdManager::EV_PRIO, EV_WRITE = detail::FdManager::EV_WRITE,
  EV_HUP = detail::FdManager::EV_HUP, EV_ERR = detail::FdManager::EV_ERR, EV_ALL
}
 
typedef boost::function< void(int)> Callback
 
- Public Types inherited from senf::scheduler::detail::FIFORunner::TaskInfo
enum  Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 }
 

Public Member Functions

void disable ()
 Disable event. More...
 
void enable ()
 Enable event. More...
 
FdEventaction (Callback const &cb)
 Change event callback. More...
 
FdEventevents (int events)
 Change event mask. More...
 
FdEventaddEvents (int events)
 Add additional events to event mask. More...
 
FdEventremoveEvents (int events)
 Remove events from event mask. More...
 
int events ()
 Current event mask. More...
 
template<class Handle >
FdEventhandle (Handle const &handle)
 Change event file handle. More...
 
- Public Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo
 TaskInfo (std::string const &name, Priority priority=PRIORITY_NORMAL)
 
virtual ~TaskInfo ()
 
void run ()
 
bool runnable () const
 
- Public Member Functions inherited from senf::scheduler::detail::Event
std::string const & name () const
 Get event name. More...
 
bool enabled () const
 true, if event is enabled, false otherwise More...
 
unsigned runCount () const
 Number of times, event was fired. More...
 
char const * type () const
 Event type code. More...
 
std::string info () const
 Additional event information. More...
 
 Event (std::string const &name)
 
virtual ~Event ()
 
- Public Member Functions inherited from senf::scheduler::detail::FdManager::Event
virtual ~Event ()
 

Structors and default members

template<class Handle >
 FdEvent (std::string const &name, Callback const &cb, Handle const &handle, int events, bool initiallyEnabled=true)
 Register a file descriptor event. More...
 
 FdEvent (std::string const &name, Callback const &cb)
 Create a file descriptor event. More...
 
 ~FdEvent ()
 

Additional Inherited Members

- Protected Member Functions inherited from senf::scheduler::detail::FIFORunner::TaskInfo
void setRunnable ()
 
- Protected Member Functions inherited from senf::scheduler::detail::Event
void countRun ()
 

Detailed Description

File descriptor event.

The FdEvent class registers a file descriptor for read or write events.

There are a number of different event types supported for file descriptors. Those are specified using a bit mask. Possible events are

  • EV_READ: File descriptor is readable (or at EOF)
  • EV_PRIO: There is out-of-band data available to be read on the file descriptor
  • EV_WRITE: File descriptor is writable

The callback will be called with one additional argument. This argument is the event mask of type int. This mask will tell, which of the registered events are signaled. There are some additional flags which can be set when calling the handler callback:

  • EV_HUP: The other end has closed the connection
  • EV_ERR: Transport error

Only a single handler may be registered for any combination of file descriptor and event otherwise a DuplicateEventRegistrationException is thrown.

The file descriptor is specified using an arbitrary handle type which supports the retrieve_filehandle() protocol: There must be a global function retrieve_filehandle callable with the handle type. This function must return the file descriptor associated with the handle. Implementations for integer numbers (explicit file descriptors) and senf socket handles are provided.

The FdEvent class is an implementation of the RAII idiom: The event will be automatically unregistered in the FdEvent destructor. The FdEvent instance should be created within the same scope or on a scope below where the callback is defined (e.g. if the callback is a member function it should be defined as a class member).

Definition at line 72 of file FdEvent.hh.

Member Typedef Documentation

◆ Callback

typedef boost::function<void (int)> senf::scheduler::FdEvent::Callback

Definition at line 81 of file FdEvent.hh.

Member Enumeration Documentation

◆ Events

Enumerator
EV_NULL 

No event.

EV_READ 

fd readable (or EOF)

EV_PRIO 

OOB data available for read.

EV_WRITE 

fd writable

EV_HUP 

remote end closed connection

EV_ERR 

transport error

EV_ALL 

register all events (read, prio and write)

Definition at line 83 of file FdEvent.hh.

Constructor & Destructor Documentation

◆ FdEvent() [1/2]

template<class Handle >
senf::scheduler::FdEvent::FdEvent ( std::string const &  name,
Callback const &  cb,
Handle const &  handle,
int  events,
bool  initiallyEnabled = true 
)

Register a file descriptor event.

Registers cb to be called when any of the events occurs on handle. If initiallyEnabled is set false, the callback will not be enabled automatically. Use enable() to do so.

Parameters
[in]nameDescriptive event name (purely informational)
[in]cbCallback to call
[in]handleHandle (file descriptor) to watch
[in]eventsEvents to watch for (see Events enum)
[in]initiallyEnabledif set false, do not enable callback automatically.

◆ FdEvent() [2/2]

senf::scheduler::FdEvent::FdEvent ( std::string const &  name,
Callback const &  cb 
)

Create a file descriptor event.

Creates a file descriptor event for callback cb. The event is initially disabled. Use the other members to set the missing parameters and enable the event.

Parameters
[in]nameDescriptive event name (purely informational)
[in]cbCallback to call. This callback may explicitly be set to 0 if the value cannot be initialized.

◆ ~FdEvent()

senf::scheduler::FdEvent::~FdEvent ( )

Member Function Documentation

◆ action()

FdEvent& senf::scheduler::FdEvent::action ( Callback const &  cb)

Change event callback.

◆ addEvents()

FdEvent& senf::scheduler::FdEvent::addEvents ( int  events)

Add additional events to event mask.

◆ disable()

void senf::scheduler::FdEvent::disable ( )

Disable event.

Definition at line 120 of file FdEvent.cc.

◆ enable()

void senf::scheduler::FdEvent::enable ( )

Enable event.

Definition at line 130 of file FdEvent.cc.

◆ events() [1/2]

senf::scheduler::FdEvent & senf::scheduler::FdEvent::events ( int  events)

Change event mask.

Definition at line 140 of file FdEvent.cc.

◆ events() [2/2]

int senf::scheduler::FdEvent::events ( )

Current event mask.

◆ handle()

template<class Handle >
FdEvent& senf::scheduler::FdEvent::handle ( Handle const &  handle)

Change event file handle.

◆ removeEvents()

FdEvent& senf::scheduler::FdEvent::removeEvents ( int  events)

Remove events from event mask.


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