Event dispatcher.
More...
|
| dispatcher () throw () |
| Creates a default dispatcher (with just 1 priority). More...
|
|
| dispatcher (int npriorities) throw (std::bad_alloc) |
| Creates a dispatcher with npriorities priorities. More...
|
|
| ~dispatcher () throw () |
| Free dispatcher resources, see Status section for details. More...
|
|
void | add (basic_event &e, int priority=DEFAULT_PRIORITY) throw (invalid_priority) |
| Adds an event to the dispatcher. More...
|
|
void | add (basic_event &e, const time &to, int priority=DEFAULT_PRIORITY) throw (invalid_priority) |
| Adds an event to the dispatcher with a timeout. More...
|
|
template<typename F > |
void | add_once (int fd, type ev, F &handler) |
| Adds a temporary event. More...
|
|
void | add_once (int fd, type ev, ccallback_type handler, void *arg) |
| Adds a temporary event to with a C-style callback. More...
|
|
template<typename F > |
void | add_once (int fd, type ev, F &handler, const time &to) |
| Adds a temporary event. More...
|
|
void | add_once (int fd, type ev, ccallback_type handler, void *arg, const time &to) |
| Adds a temporary event with a C-style callback. More...
|
|
template<typename F > |
void | add_once_timer (F &handler, const time &to) |
| Adds a temporary timer. More...
|
|
void | add_once_timer (ccallback_type handler, void *arg, const time &to) |
| Adds a temporary timer with a C-style callback. More...
|
|
void | del (basic_event &e) throw () |
| Removes an event. More...
|
|
int | dispatch (int flags=0) throw () |
| Main dispatcher loop. More...
|
|
int | exit (const time &to=time()) throw () |
| Exit the dispatch() loop. More...
|
|
Event dispatcher.
This class is the responsible for looping and dispatching events. Every time you need an event loop you should create an instance of this class.
You can add events to the dispatcher, and you can remove them later or you can add events to be processed just once . You can loop once or forever (well, of course you can break that forever removing all the events or by exiting the loop ).
- Examples
- bench.cpp, c-way.cpp, functor-way.cpp, mixed-way.cpp, prio-test.cpp, test-eof.cpp, test-time.cpp, test-weof.cpp, trivial.cpp, and wrapped-functor-way.cpp.
◆ dispatcher() [1/2]
eventxx::dispatcher::dispatcher |
( |
| ) |
|
throw | ( | |
| ) | | |
|
inline |
Creates a default dispatcher (with just 1 priority).
- See also
- dispatcher(int) if you want to create a dispatcher with more priorities.
◆ dispatcher() [2/2]
eventxx::dispatcher::dispatcher |
( |
int |
npriorities | ) |
|
throw | ( | std::bad_alloc |
| ) | | |
|
inline |
Creates a dispatcher with npriorities priorities.
- Parameters
-
npriorities | Number of priority queues to use. |
◆ ~dispatcher()
eventxx::dispatcher::~dispatcher |
( |
| ) |
|
throw | ( | |
| ) | | |
|
inline |
Free dispatcher resources, see Status section for details.
◆ add() [1/2]
Adds an event to the dispatcher with a timeout.
The event is fired when there is activity on e or when to has elapsed, whatever come first.
- Parameters
-
e | Event to add. |
to | Timeout. |
priority | Priority of the event. |
References eventxx::DEFAULT_PRIORITY.
◆ add() [2/2]
◆ add_once() [1/4]
void eventxx::dispatcher::add_once |
( |
int |
fd, |
|
|
type |
ev, |
|
|
ccallback_type |
handler, |
|
|
void * |
arg |
|
) |
| |
|
inline |
Adds a temporary event to with a C-style callback.
Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.
- Parameters
-
fd | File descriptor to monitor for events. |
ev | Type of events to monitor. |
handler | Callback function. |
arg | Arbitrary pointer to pass to the handler as argument. |
◆ add_once() [2/4]
Adds a temporary event with a C-style callback.
Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.
- Parameters
-
fd | File descriptor to monitor for events. |
ev | Type of events to monitor. |
handler | Callback function. |
arg | Arbitrary pointer to pass to the handler as argument. |
to | Timeout. |
◆ add_once() [3/4]
template<typename F >
void eventxx::dispatcher::add_once |
( |
int |
fd, |
|
|
type |
ev, |
|
|
F & |
handler |
|
) |
| |
|
inline |
Adds a temporary event.
Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.
- Parameters
-
fd | File descriptor to monitor for events. |
ev | Type of events to monitor. |
handler | Callback function. |
◆ add_once() [4/4]
template<typename F >
void eventxx::dispatcher::add_once |
( |
int |
fd, |
|
|
type |
ev, |
|
|
F & |
handler, |
|
|
const time & |
to |
|
) |
| |
|
inline |
Adds a temporary event.
Adds a temporary event, without the need of instantiating a new event object. Events added this way can't eventxx::PERSIST.
- Parameters
-
fd | File descriptor to monitor for events. |
ev | Type of events to monitor. |
handler | Callback function. |
to | Timeout. |
◆ add_once_timer() [1/2]
void eventxx::dispatcher::add_once_timer |
( |
ccallback_type |
handler, |
|
|
void * |
arg, |
|
|
const time & |
to |
|
) |
| |
|
inline |
Adds a temporary timer with a C-style callback.
Adds a temporary timer, without the need of instantiating a new timer object.
- Parameters
-
handler | Callback function. |
arg | Arbitrary pointer to pass to the handler as argument. |
to | Timer's timeout. |
◆ add_once_timer() [2/2]
template<typename F >
void eventxx::dispatcher::add_once_timer |
( |
F & |
handler, |
|
|
const time & |
to |
|
) |
| |
|
inline |
Adds a temporary timer.
Adds a temporary timer, without the need of instantiating a new timer object.
- Parameters
-
handler | Callback function. |
to | Timer's timeout. |
◆ del()
void eventxx::dispatcher::del |
( |
basic_event & |
e | ) |
|
throw | ( | |
| ) | | |
|
inline |
Removes an event.
The event e will be no longer monitored by this dispatcher.
- Parameters
-
- Examples
- bench.cpp, and test-time.cpp.
◆ dispatch()
int eventxx::dispatcher::dispatch |
( |
int |
flags = 0 | ) |
|
throw | ( | |
| ) | | |
|
inline |
Main dispatcher loop.
This function takes the control of the program, waiting for an event and calling its callbacks when it's fired. It only returns under this conditions:
- Parameters
-
flags | If eventxx::ONCE is specified, then just one event is processed, if eventxx::NONBLOCK is specified, then this function returns even if there are no pending events. |
- Returns
- 0 if eventxx::NONBLOCK or eventxx::ONCE is set, 1 if there are no more events registered and EINTR if you use the libevent's
event_gotsig
and return -1 in your event_sigcb
callback.
- Examples
- bench.cpp, c-way.cpp, mixed-way.cpp, test-eof.cpp, test-time.cpp, test-weof.cpp, and trivial.cpp.
◆ exit()
int eventxx::dispatcher::exit |
( |
const time & |
to = time() | ) |
|
throw | ( | |
| ) | | |
|
inline |
Exit the dispatch() loop.
- Parameters
-
to | If a timeout is given, the loop exits after the specified time is elapsed. |
- Returns
- Not very well specified by libevent :-/ that's why it doesn't throw an exception either.
- Examples
- c-way.cpp, and mixed-way.cpp.
The documentation for this struct was generated from the following file: