senf::scheduler::FdEvent Class Reference

File descriptor event. More...

#include <senf/Scheduler/FdEvent.hh>

Inheritance diagram for senf::scheduler::FdEvent:
Inheritance graph
[legend]

List of all members.


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 82 of file FdEvent.hh.


Classes

struct   DuplicateEventRegistrationException

Public Types

enum   Events {
  EV_NONE = 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 Member Functions

void  disable ()
  Disable event.
void  enable ()
  Enable event.
FdEvent action (Callback const &cb)
  Change event callback.
FdEvent events (int events)
  Change event mask.
FdEvent addEvents (int events)
  Add additional events to event mask.
FdEvent removeEvents (int events)
  Remove events from event mask.
int  events ()
  Current event mask.
template<class Handle >
FdEvent handle (Handle const &handle)
  Change event file handle.

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.
  FdEvent (std::string const &name, Callback const &cb)
  Create a file descriptor event.
  ~FdEvent ()

Member Typedef Documentation

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

Definition at line 91 of file FdEvent.hh.


Member Enumeration Documentation

enum senf::scheduler::FdEvent::
Events
Enumerator:
EV_NONE  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 93 of file FdEvent.hh.


Constructor & Destructor Documentation

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]  name  Descriptive event name (purely informational)
[in]  cb  Callback to call
[in]  handle  Handle (file descriptor) to watch
[in]  events  Events to watch for (see Events enum)
[in]  initiallyEnabled  if set false, do not enable callback automatically.

Definition at line 37 of file FdEvent.cti.

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]  name  Descriptive event name (purely informational)
[in]  cb  Callback to call. This callback may explicitly be set to 0 if the value cannot be initialized.

Definition at line 37 of file FdEvent.cci.

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

Definition at line 41 of file FdEvent.cci.


Member Function Documentation

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

Change event callback.

Definition at line 47 of file FdEvent.cci.

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

Add additional events to event mask.

Definition at line 53 of file FdEvent.cci.

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

Disable event.

Definition at line 129 of file FdEvent.cc.

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

Enable event.

Definition at line 139 of file FdEvent.cc.

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

Current event mask.

Definition at line 65 of file FdEvent.cci.

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

Change event mask.

Definition at line 149 of file FdEvent.cc.

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

Change event file handle.

Definition at line 37 of file FdEvent.ct.

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

Remove events from event mask.

Definition at line 59 of file FdEvent.cci.


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