#include <senf/Scheduler/FdEvent.hh>
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 descriptorEV_WRITE:
File descriptor is writableEV_HUP:
The other end has closed the connectionEV_ERR:
Transport errorThe 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 () |
typedef boost::function<void (int)> senf::scheduler::FdEvent:: | ||||
Callback | ||||
Definition at line 91 of file FdEvent.hh.
enum senf::scheduler::FdEvent:: | ||||
Events | ||||
Definition at line 93 of file FdEvent.hh.
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.
[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.
[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.
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.
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.