Base class for IO services. More...
#include <ciosrv.h>
Public Member Functions | |
ciosrv (pthread_t tid=0) | |
Initializes all structures for this ciosrv object. | |
virtual | ~ciosrv () |
Deallocates resources for this ciosrv object. | |
ciosrv (const ciosrv &iosrv) | |
Initializes all structures for this ciosrv object. | |
ciosrv & | operator= (const ciosrv &iosrv) |
void | notify (const cevent &event) |
Sends a notification to this ciosrv instance. More... | |
pthread_t | get_thread_id () const |
Returns thread-id of local thread. More... | |
Protected Member Functions | |
ctimer | get_next_timer () |
Event handlers | |
These methods define handlers for file descriptor and cevent notifications. Derived classes should overwwrite all relevant handlers. | |
virtual void | handle_event (const rofl::cevent &event) |
Handler for event notifications using cevent instances. More... | |
virtual void | handle_revent (int fd) |
Handler for read events on file descriptors. More... | |
virtual void | handle_wevent (int fd) |
Handler for write events on file descriptors. More... | |
virtual void | handle_xevent (int fd) |
Handler for exceptions on file descriptors. More... | |
virtual void | handle_timeout (int opaque, void *data=(void *) 0) |
Handler for timer events. More... | |
Management methods for file descriptors | |
void | register_filedesc_r (int fd) |
Registers a file descriptor for read events. More... | |
void | deregister_filedesc_r (int fd) |
Deregisters a file descriptor from read events. More... | |
void | register_filedesc_w (int fd) |
Registers a file descriptor for write events. More... | |
void | deregister_filedesc_w (int fd) |
Deregisters a file descriptor from write events. More... | |
Management methods for timers and events | |
const rofl::ctimerid & | register_timer (int opaque, const rofl::ctimespec ×pec) |
Installs a new timer to fire in t seconds. More... | |
const rofl::ctimerid & | reset_timer (const rofl::ctimerid &timer_id, const rofl::ctimespec ×pec) |
Resets a running timer of type opaque. More... | |
ctimerid & | restart_timer (rofl::ctimerid &timer_id, int opaque, const rofl::ctimespec ×pec) |
Resets an existing or creates a new timer. More... | |
bool | pending_timer (const rofl::ctimerid &timer_id) |
Checks for a pending timer of type opaque. More... | |
void | cancel_timer (const rofl::ctimerid &timer_id) |
Cancels a pending timer. More... | |
void | cancel_all_timers () |
Cancels all pending timers of this instance. | |
void | cancel_all_events () |
Cancels all pending events of this instance. | |
Friends | |
class | cioloop |
std::ostream & | operator<< (std::ostream &os, const ciosrv &iosvc) |
Base class for IO services.
Derive from this class in order to get support for file/socket descriptor and timer management. rofl::ciosrv binds a higher layer class with the low layer IO loop defined inside class rofl::cioloop. This class provides two groups of methods:
Methods for file descriptor management:
1.a) register_filedesc_r() register a descriptor for read IO
1.b) deregister_filedesc_r() deregister a read descriptor
1.c) register_filedesc_w() register a descriptor for write IO
1.d) deregister_filedesc_w() deregister a write descriptor
Methods for timer management:
1.e) register_timer() register a timer
1.f) reset_timer() reset a timer
1.g) restart_timer() restart or create new timer
1.h) pending_timer() check for existence of timer
1.i) cancel_timer() cancel a timer
1.j) cancel_all_timer() cancel all timers
Methods for event management:
1.k) notify() send an event to this rofl::ciosrv instance
The following event handlers exist and may be overwritten by a class deriving from rofl::ciosrv:
2.a) handle_revent() read events on file descriptor(s)
2.b) handle_wevent() write events on file descriptor(s)
2.c) handle_xevent() exceptions on file descriptor(s)
2.d) handle_timeout() timeout event(s)
2.e) handle_event() events sent via notify() method
This class utilizes timer handles based on class rofl::ctimerid for managing pending timers, e.g., cancel or restarting them.
|
inlineprotected |
Cancels a pending timer.
opaque | timer type the caller is seeking for |
|
inlineprotected |
Deregisters a file descriptor from read events.
fd | the file descriptor removed from the set of read events |
|
inlineprotected |
Deregisters a file descriptor from write events.
fd | the file descriptor removed from the set of write events |
|
inline |
Returns thread-id of local thread.
|
inlineprotectedvirtual |
Handler for event notifications using cevent instances.
To be overwritten by derived class. Default behaviour: event is ignored.
event | rofl::cevent instance received |
|
inlineprotectedvirtual |
Handler for read events on file descriptors.
To be overwritten by derived class. Default behaviour: event is ignored.
fd | read event occured on file descriptor fd |
|
inlineprotectedvirtual |
Handler for timer events.
To be overwritten by derived class. Default behaviour: event is ignored.
opaque | expired timer type |
data | pointer to opaque data |
|
inlineprotectedvirtual |
Handler for write events on file descriptors.
To be overwritten by derived class. Default behaviour: event is ignored.
fd | write event occured on file descriptor fd |
|
inlineprotectedvirtual |
Handler for exceptions on file descriptors.
To be overwritten by derived class. Default behaviour: event is ignored.
fd | exception occured on file descriptor fd |
|
inline |
Sends a notification to this ciosrv instance.
Method notify() can be called from every thread within the running application. The event management system wakes up this thread when in sleeping condition in a poll/select loop and calls its handle_event() method.
ev | the event to be sent to this instance |
|
inlineprotected |
Checks for a pending timer of type opaque.
opaque | timer type the caller is seeking for |
|
inlineprotected |
Registers a file descriptor for read events.
A read event will be indicated via calling handle_revent(fd).
fd | the file descriptor waiting for read events |
|
inlineprotected |
Registers a file descriptor for write events.
A write event will be indicated via calling handle_wevent(fd).
fd | the file descriptor waiting for write events |
|
inlineprotected |
Installs a new timer to fire in t seconds.
opaque | this timer type can be arbitrarily chosen |
ctimer | object |
|
inlineprotected |
Resets a running timer of type opaque.
If no timer of type opaque exists, a new timer will be started.
opaque | this timer type can be arbitrarily chosen |
t | timeout in seconds of this timer |
|
inlineprotected |
Resets an existing or creates a new timer.
If timer specified by timer_id exists, the timer is reset to the value defined by timespec. If no timer of the specified timer_id exists, a new timer is created based on values opaque and timespec.
timer_id | An existing timer_id. This value is going to be overwritten. |
opaque | this timer type value can be chosen by the caller |
timespec | timeout defined for this timer |