21# include <sys/resource.h>
78 const std::string&
name_ =
"<unknown>");
An abstract interface for handling I/O events, timers, and such.
Bundles file descriptor mask sets to be used with select().
Singleton template class allows to turn any new or existing class T into Singleton Pattern.
TimerCountdown class keep the track of the elapsed time.
TimerQueue class represents the queue of Timers that application can install for Reactor to dispatch.
A wrapper class to provide AutoPtr with reference semantics.
void calculateTimeout(TimeVal *&howlong_, TimeVal *maxwait_)
Calculate closest timeout.
bool registerIOHandler(EventHandler *eh_, handler_t fd_, EventType et_=RWE_EVENTS)
Register I/O Event handler with Reactor.
TimerQueue m_tqueue
The queue of Timers.
MaskSet m_waitSet
Handlers to wait for event on.
Fd2Eh_Map_Type m_writeSet
Event handlers awaiting on WRITE_EVENT.
Fd2Eh_Map_Type::iterator Fd2Eh_Map_Iter
MaskSet m_readySet
Handlers that are ready for processing.
void waitForEvents(void)
Main waiting loop that blocks indefinitely processing events.
handler_t m_maxfd_plus1
Max file descriptor number (in all sets) plus 1.
void dispatchHandler(FdSet &mask_, Fd2Eh_Map_Type &fdSet_, EH_IO_Callback callback_)
Call handler's callback and, if callback returns negative value, remove it from the Reactor.
int m_fd_setsize
Max number of open files per process.
bool handleError(void)
Handle error in select(2) loop appropriately.
std::map< u_int, EventHandler * > Fd2Eh_Map_Type
no cloning
void deactivate(void)
Deactivate Reactor.
bool dispatch(int minimum_)
Notify all EventHandlers registered on respecful events occured.
Reactor & operator=(const Reactor &)
no cloning
Fd2Eh_Map_Type m_readSet
Event handlers awaiting on READ_EVENT.
bool m_active
Flag that indicates whether Reactor is active or had been stopped.
void stopReactor(void)
Stop Reactor's activity.
TimerId registerTimerHandler(EventHandler *eh_, const TimeVal &tv_, const std::string &name_="<unknown>")
Register Timer Event handler with Reactor.
bool checkFDs(void)
Check mask for bad file descriptors.
int isAnyReady(void)
Return number of file descriptors ready accross all sets.
bool removeHandler(EventHandler *eh_, EventType et_=ALL_EVENTS)
Remove Event handler from reactor for either all I/O events or timeout event or both.
bool removeTimerHandler(TimerId id_)
Remove Timer event from the queue.
void adjust_maxfdp1(handler_t fd_)
Adjust maxfdp1 in a portable way (win32 ignores maxfd alltogether).
bool removeIOHandler(handler_t fd_)
Remove IO Event handler from reactor.
Fd2Eh_Map_Type m_exceptSet
Event handlers awaiting on EXCEPT_EVENT.
EventType
EventType defines events types that Reactor understands.
@ ALL_EVENTS
Mask that includes all events.
@ RWE_EVENTS
READ_EVENT | WRITE_EVENT | EXCEPT_EVENT
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
int(EventHandler::* EH_IO_Callback)(int)
A type for the pointer to I/O-related callback member function of class EventHandler.